diff --git a/editors/vscode/src/browser-lsp-worker.ts b/editors/vscode/src/browser-lsp-worker.ts index 38ea388db..968936a8e 100644 --- a/editors/vscode/src/browser-lsp-worker.ts +++ b/editors/vscode/src/browser-lsp-worker.ts @@ -1,46 +1,34 @@ // Copyright © SixtyFPS GmbH // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial +import slint_init, * as slint_lsp from "../out/slint_lsp_wasm.js"; +import slint_wasm_data from "../out/slint_lsp_wasm_bg.wasm"; +import { InitializeParams, InitializeResult } from "vscode-languageserver"; import { createConnection, BrowserMessageReader, BrowserMessageWriter, } from "vscode-languageserver/browser"; -import { InitializeParams, InitializeResult } from "vscode-languageserver"; - -import slint_init, * as slint_lsp from "../out/slint_lsp_wasm.js"; -import slint_wasm_data from "../out/slint_lsp_wasm_bg.wasm"; - slint_init(slint_wasm_data).then((_) => { - const messageReader = new BrowserMessageReader(self); - const messageWriter = new BrowserMessageWriter(self); - const connection = createConnection(messageReader, messageWriter); + const reader = new BrowserMessageReader(self); + const writer = new BrowserMessageWriter(self); let the_lsp: slint_lsp.SlintServer; + const connection = createConnection(reader, writer); + function send_notification(method: string, params: any): boolean { connection.sendNotification(method, params); return true; } - async function load_file(path: string): Promise { - const contents: Uint8Array = await connection.sendRequest( - "slint/load_file", - path, - ); - return new TextDecoder().decode(contents); - } - - async function send_request(method: string, params: any): Promise { + async function send_request(method: string, params: any): Promise { return await connection.sendRequest(method, params); } - function highlight(path: string, offset: number) { - connection.sendRequest("slint/preview_message", { - command: "highlight", - data: { path: path, offset: offset }, - }); + async function load_file(path: string): Promise { + return await connection.sendRequest("slint/load_file", path); } connection.onInitialize((params: InitializeParams): InitializeResult => { @@ -49,7 +37,6 @@ slint_init(slint_wasm_data).then((_) => { send_notification, send_request, load_file, - highlight, ); return the_lsp.server_initialize_result(params.capabilities); }); @@ -58,9 +45,13 @@ slint_init(slint_wasm_data).then((_) => { return await the_lsp.handle_request(token, method, params); }); - connection.onDidChangeConfiguration(async (_) => { - the_lsp.reload_config(); - }); + connection.onNotification( + "slint/preview_to_lsp", + // eslint-disable-next-line @typescript-eslint/no-explicit-any + async (params: any) => { + await the_lsp.process_preview_to_lsp_message(params); + }, + ); connection.onDidChangeTextDocument(async (param) => { await the_lsp.reload_document( @@ -78,6 +69,10 @@ slint_init(slint_wasm_data).then((_) => { ); }); + connection.onDidChangeConfiguration(async (_param: unknown) => { + the_lsp.reload_config(); + }); + // Listen on the connection connection.listen(); diff --git a/editors/vscode/src/browser.ts b/editors/vscode/src/browser.ts index 7b53ca620..b82d2f116 100644 --- a/editors/vscode/src/browser.ts +++ b/editors/vscode/src/browser.ts @@ -64,6 +64,7 @@ function startClient( let contents = await vscode.workspace.fs.readFile( Uri.parse(param, true), ); + return new TextDecoder().decode(contents); }); });