From fb862315139d90eb349f4445b1efad2207c74456 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Mon, 30 May 2022 10:36:48 +0200 Subject: [PATCH 1/2] ensure updated config is synced on use of restart command, and clean up a few unused things --- client/src/extension.ts | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/client/src/extension.ts b/client/src/extension.ts index 01e9c664a..1a6b40a6b 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -97,7 +97,7 @@ export function activate(context: ExtensionContext) { "ReScriptLSP", "ReScript Language Server", serverOptions, - clientOptions + createClientOptions() ); attachCodeAnalysis(client); return client; @@ -122,21 +122,20 @@ export function activate(context: ExtensionContext) { }, }; - // Options to control the language client - let clientOptions: LanguageClientOptions = { - // Register the server for plain text documents - documentSelector: [{ scheme: "file", language: "rescript" }], - synchronize: { - // Notify the server about file changes to '.clientrc files contained in the workspace - fileEvents: workspace.createFileSystemWatcher("**/.clientrc"), - }, - // We'll send the initial configuration in here, but this might be - // problematic because every consumer of the LS will need to mimic this. - // We'll leave it like this for now, but might be worth revisiting later on. - initializationOptions: { - extensionConfiguration: workspace.getConfiguration("rescript.settings"), - }, - }; + function createClientOptions() { + // Options to control the language client + let clientOptions: LanguageClientOptions = { + documentSelector: [{ scheme: "file", language: "rescript" }], + // We'll send the initial configuration in here, but this might be + // problematic because every consumer of the LS will need to mimic this. + // We'll leave it like this for now, but might be worth revisiting later on. + initializationOptions: { + extensionConfiguration: workspace.getConfiguration("rescript.settings"), + }, + }; + + return clientOptions; + } // Create the language client and start the client. client = createLanguageClient(); From 008596c5b2fdfa28a10974d9abd549e65684fce4 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Mon, 30 May 2022 13:44:37 +0200 Subject: [PATCH 2/2] move all needed things into createLanguageClient --- client/src/extension.ts | 83 +++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 45 deletions(-) diff --git a/client/src/extension.ts b/client/src/extension.ts index 1a6b40a6b..95df665a4 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -69,7 +69,44 @@ let client: LanguageClient; // }); export function activate(context: ExtensionContext) { - function attachCodeAnalysis(client: LanguageClient) { + function createLanguageClient() { + // The server is implemented in node + let serverModule = context.asAbsolutePath( + path.join("server", "out", "server.js") + ); + // The debug options for the server + // --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging + let debugOptions = { execArgv: ["--nolazy", "--inspect=6009"] }; + + // If the extension is launched in debug mode then the debug server options are used + // Otherwise the run options are used + let serverOptions: ServerOptions = { + run: { module: serverModule, transport: TransportKind.ipc }, + debug: { + module: serverModule, + transport: TransportKind.ipc, + options: debugOptions, + }, + }; + + // Options to control the language client + let clientOptions: LanguageClientOptions = { + documentSelector: [{ scheme: "file", language: "rescript" }], + // We'll send the initial configuration in here, but this might be + // problematic because every consumer of the LS will need to mimic this. + // We'll leave it like this for now, but might be worth revisiting later on. + initializationOptions: { + extensionConfiguration: workspace.getConfiguration("rescript.settings"), + }, + }; + + const client = new LanguageClient( + "ReScriptLSP", + "ReScript Language Server", + serverOptions, + clientOptions + ); + // This sets up a listener that, if we're in code analysis mode, triggers // code analysis as the LS server reports that ReScript compilation has // finished. This is needed because code analysis must wait until @@ -89,54 +126,10 @@ export function activate(context: ExtensionContext) { }) ); }); - } - /** creates a language client and attaches code analysis */ - function createLanguageClient() { - const client = new LanguageClient( - "ReScriptLSP", - "ReScript Language Server", - serverOptions, - createClientOptions() - ); - attachCodeAnalysis(client); return client; } - // The server is implemented in node - let serverModule = context.asAbsolutePath( - path.join("server", "out", "server.js") - ); - // The debug options for the server - // --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging - let debugOptions = { execArgv: ["--nolazy", "--inspect=6009"] }; - - // If the extension is launched in debug mode then the debug server options are used - // Otherwise the run options are used - let serverOptions: ServerOptions = { - run: { module: serverModule, transport: TransportKind.ipc }, - debug: { - module: serverModule, - transport: TransportKind.ipc, - options: debugOptions, - }, - }; - - function createClientOptions() { - // Options to control the language client - let clientOptions: LanguageClientOptions = { - documentSelector: [{ scheme: "file", language: "rescript" }], - // We'll send the initial configuration in here, but this might be - // problematic because every consumer of the LS will need to mimic this. - // We'll leave it like this for now, but might be worth revisiting later on. - initializationOptions: { - extensionConfiguration: workspace.getConfiguration("rescript.settings"), - }, - }; - - return clientOptions; - } - // Create the language client and start the client. client = createLanguageClient();