Skip to content

Commit 32981d2

Browse files
committed
feat(frontend/lsp): handle progress and messages
1 parent 567b253 commit 32981d2

File tree

14 files changed

+153
-3
lines changed

14 files changed

+153
-3
lines changed

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
"events": "3.3.0",
4848
"frontend-wasm": "file:../frontend-wasm/pkg/",
4949
"marked": "^16.1.2",
50-
"solid-js": "^1.9.0"
50+
"solid-js": "^1.9.0",
51+
"vscode-languageserver-protocol": "^3.17.5"
5152
},
5253
"pnpm": {
5354
"onlyBuiltDependencies": [

frontend/pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Panels } from "@features/panels/views";
99
import { Sidebar } from "@features/sidebar/views";
1010

1111
import "@features/theme/stores"
12+
import { LoadingLsp } from "@features/lsp/views";
1213

1314
const App: Component = () => {
1415
interceptAuthCallback();
@@ -20,6 +21,7 @@ const App: Component = () => {
2021
<>
2122
<Sidebar />
2223
<Panels />
24+
<LoadingLsp />
2325
</>
2426
);
2527
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./loading";
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { setLoadingLsp } from "../stores";
2+
3+
export function updateLoadingLsp(change: {title?: string, message?: string, percentage?: number}) {
4+
setLoadingLsp({
5+
isLoading: true,
6+
...change
7+
});
8+
}
9+
10+
export function endLoadingLsp() {
11+
setLoadingLsp({
12+
isLoading: false,
13+
});
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./loading";
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { createStore } from "solid-js/store";
2+
3+
export type LoadingLspStore = {
4+
isLoading: true;
5+
title: string;
6+
message: string;
7+
percentage?: number;
8+
} | {
9+
isLoading: false;
10+
title?: string;
11+
message?: string;
12+
percentage?: number;
13+
};
14+
15+
export const [loadingLsp, setLoadingLsp] = createStore<LoadingLspStore>({
16+
isLoading: false,
17+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ProgressToken, WorkDoneProgress } from "vscode-languageserver-protocol";
2+
3+
export interface ProgressParams {
4+
/**
5+
* The progress token provided by the client or server.
6+
*/
7+
token: ProgressToken;
8+
/**
9+
* The progress data.
10+
*/
11+
value: typeof WorkDoneProgress.type._pr;
12+
}
13+

frontend/src/features/lsp/utils/transport.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import { ERR_UNKNOWN } from "@open-rpc/client-js/build/Error";
99

1010
import { onWsMessage, sendMessage } from "@features/ws/services";
1111
import { ClientMessageKind, ServerMessageKind } from "@features/ws/types";
12+
import { ProgressParams } from "../types";
13+
import { endLoadingLsp, updateLoadingLsp } from "../services";
14+
import { MessageType, ShowMessageParams } from "vscode-languageserver-protocol";
15+
import { showToast, ToastKind } from "@services/toast";
1216

1317
const ignoredNotify = {
1418
"textDocument/didOpen": "open",
@@ -18,11 +22,57 @@ const ignoredNotify = {
1822
export class RsLspTransport extends Transport {
1923
public async connect(): Promise<void> {
2024
onWsMessage(ServerMessageKind.Lsp, ({ data }) => {
25+
if (
26+
"method" in data && "params" in data &&
27+
this.handleWorkDone(data.method as string, data.params)
28+
) {
29+
return;
30+
}
31+
2132
// @ts-expect-error -- resolveRes is private, but needed for performance issues
2233
this.transportRequestManager.resolveRes(data);
2334
});
2435
}
2536

37+
private handleWorkDone(method: string, params_: unknown): boolean {
38+
if (method == "window/showMessage") {
39+
let params = params_ as ShowMessageParams;
40+
41+
let kind: ToastKind = "info";
42+
43+
if (params.type == MessageType.Debug) {
44+
kind = "debug";
45+
} else if (params.type == MessageType.Error) {
46+
kind = "error";
47+
} else if (params.type == MessageType.Warning) {
48+
kind = "warn";
49+
}
50+
51+
showToast(kind, { text: params.message });
52+
53+
return true;
54+
}
55+
56+
if (method != "$/progress") {
57+
return false;
58+
}
59+
60+
const progress = (params_ as ProgressParams).value;
61+
62+
if (progress.kind == "begin") {
63+
updateLoadingLsp({ title: progress.title, message: "" });
64+
} else if (progress.kind == "report") {
65+
updateLoadingLsp({
66+
message: progress.message,
67+
percentage: progress.percentage,
68+
});
69+
} else if (progress.kind == "end") {
70+
endLoadingLsp();
71+
}
72+
73+
return true;
74+
}
75+
2676
public async sendData(
2777
data: JSONRPCRequestData,
2878
timeout: number | null = 5000,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@import "../../../styles/_mixins.sass"
2+
3+
.container
4+
position: absolute
5+
right: 1rem
6+
bottom: 1rem
7+
8+
display: flex
9+
flex-direction: column
10+
align-items: flex-end
11+
12+
font-size: 0.9rem
13+
color: var(--colors-gray-300)
14+
15+
.title
16+
display: flex
17+
align-items: center
18+
gap: 0.25rem
19+
20+
.message
21+
padding-right: 0.3rem
22+
text-align: end

0 commit comments

Comments
 (0)