Skip to content

Commit 499a8a7

Browse files
committed
vscode: Fix biome linter error in VSCode ectension
Biome was raising this error: > A "floating" Promise was found, meaning it is not properly handled and > could lead to ignored errors or unexpected behavior. Biome is of course right, so handle errors by logging them.
1 parent db6f436 commit 499a8a7

File tree

1 file changed

+81
-72
lines changed

1 file changed

+81
-72
lines changed

editors/vscode/src/browser-lsp-worker.ts

Lines changed: 81 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -11,86 +11,95 @@ import {
1111
BrowserMessageWriter,
1212
} from "vscode-languageserver/browser";
1313

14-
slint_init(slint_wasm_data).then((_) => {
15-
const reader = new BrowserMessageReader(self);
16-
const writer = new BrowserMessageWriter(self);
14+
slint_init(slint_wasm_data)
15+
.then((_) => {
16+
const reader = new BrowserMessageReader(self);
17+
const writer = new BrowserMessageWriter(self);
1718

18-
let the_lsp: slint_lsp.SlintServer;
19+
let the_lsp: slint_lsp.SlintServer;
1920

20-
const connection = createConnection(reader, writer);
21+
const connection = createConnection(reader, writer);
2122

22-
function send_notification(method: string, params: any): boolean {
23-
connection.sendNotification(method, params);
24-
return true;
25-
}
26-
27-
async function send_request(method: string, params: any): Promise<unknown> {
28-
return await connection.sendRequest(method, params);
29-
}
30-
31-
async function load_file(path: string): Promise<string> {
32-
return await connection.sendRequest("slint/load_file", path);
33-
}
34-
35-
connection.onInitialize((params: InitializeParams): InitializeResult => {
36-
the_lsp = slint_lsp.create(
37-
params,
38-
send_notification,
39-
send_request,
40-
load_file,
41-
);
42-
43-
setTimeout(() => {
44-
the_lsp.startup_lsp();
45-
}, 0);
46-
47-
return the_lsp.server_initialize_result(params.capabilities);
48-
});
49-
50-
connection.onRequest(async (method, params, token) => {
51-
return await the_lsp.handle_request(token, method, params);
52-
});
23+
function send_notification(method: string, params: any): boolean {
24+
connection.sendNotification(method, params);
25+
return true;
26+
}
5327

54-
connection.onNotification(
55-
"slint/preview_to_lsp",
56-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
57-
async (params: any) => {
58-
await the_lsp.process_preview_to_lsp_message(params);
59-
},
60-
);
61-
connection.onDidChangeWatchedFiles(async (param) => {
62-
for (const event of param.changes) {
63-
await the_lsp.trigger_file_watcher(event.uri, event.type);
28+
async function send_request(
29+
method: string,
30+
params: any,
31+
): Promise<unknown> {
32+
return await connection.sendRequest(method, params);
6433
}
65-
});
6634

67-
connection.onDidOpenTextDocument(async (param) => {
68-
await the_lsp.open_document(
69-
param.textDocument.text,
70-
param.textDocument.uri,
71-
param.textDocument.version,
72-
);
73-
});
35+
async function load_file(path: string): Promise<string> {
36+
return await connection.sendRequest("slint/load_file", path);
37+
}
7438

75-
connection.onDidChangeTextDocument(async (param) => {
76-
await the_lsp.reload_document(
77-
param.contentChanges[param.contentChanges.length - 1].text,
78-
param.textDocument.uri,
79-
param.textDocument.version,
39+
connection.onInitialize(
40+
(params: InitializeParams): InitializeResult => {
41+
the_lsp = slint_lsp.create(
42+
params,
43+
send_notification,
44+
send_request,
45+
load_file,
46+
);
47+
48+
setTimeout(() => {
49+
the_lsp.startup_lsp();
50+
}, 0);
51+
52+
return the_lsp.server_initialize_result(params.capabilities);
53+
},
8054
);
81-
});
8255

83-
connection.onDidCloseTextDocument(async (param) => {
84-
await the_lsp.close_document(param.textDocument.uri);
85-
});
56+
connection.onRequest(async (method, params, token) => {
57+
return await the_lsp.handle_request(token, method, params);
58+
});
8659

87-
connection.onDidChangeConfiguration(async (_param: unknown) => {
88-
await the_lsp.reload_config();
60+
connection.onNotification(
61+
"slint/preview_to_lsp",
62+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
63+
async (params: any) => {
64+
await the_lsp.process_preview_to_lsp_message(params);
65+
},
66+
);
67+
connection.onDidChangeWatchedFiles(async (param) => {
68+
for (const event of param.changes) {
69+
await the_lsp.trigger_file_watcher(event.uri, event.type);
70+
}
71+
});
72+
73+
connection.onDidOpenTextDocument(async (param) => {
74+
await the_lsp.open_document(
75+
param.textDocument.text,
76+
param.textDocument.uri,
77+
param.textDocument.version,
78+
);
79+
});
80+
81+
connection.onDidChangeTextDocument(async (param) => {
82+
await the_lsp.reload_document(
83+
param.contentChanges[param.contentChanges.length - 1].text,
84+
param.textDocument.uri,
85+
param.textDocument.version,
86+
);
87+
});
88+
89+
connection.onDidCloseTextDocument(async (param) => {
90+
await the_lsp.close_document(param.textDocument.uri);
91+
});
92+
93+
connection.onDidChangeConfiguration(async (_param: unknown) => {
94+
await the_lsp.reload_config();
95+
});
96+
97+
// Listen on the connection
98+
connection.listen();
99+
100+
// Now that we listen, the client is ready to send the init message
101+
self.postMessage("OK");
102+
})
103+
.catch((error) => {
104+
console.log("Web-Worker error:", error);
89105
});
90-
91-
// Listen on the connection
92-
connection.listen();
93-
94-
// Now that we listen, the client is ready to send the init message
95-
self.postMessage("OK");
96-
});

0 commit comments

Comments
 (0)