From cc8245563f36bd4f46c65e357bdc5c86e5dc483f Mon Sep 17 00:00:00 2001 From: Alexander Schulz-Rosengarten Date: Fri, 11 Nov 2022 16:29:02 +0100 Subject: [PATCH] Fixed and tested LDS integration via socket --- .vscode/launch.json | 14 ++++++++++++++ src/extension.ts | 13 +++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 7dca8e1e8..1c118d3b9 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,6 +12,20 @@ "request": "launch", "type": "extensionHost" }, + { + "env": { + "LF_LS_PORT": "7670" + }, + "args": [ + "--extensionDevelopmentPath=${workspaceFolder}" + ], + "name": "Launch Extension (Socket)", + "outFiles": [ + "${workspaceFolder}/out/**/*.js" + ], + "request": "launch", + "type": "extensionHost" + }, { "args": [ "--extensionDevelopmentPath=${workspaceFolder}", diff --git a/src/extension.ts b/src/extension.ts index c3853b64a..7bb42c8f4 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -6,13 +6,15 @@ import * as fs from 'fs'; import { Trace } from 'vscode-jsonrpc'; import * as vscode from 'vscode'; -import { LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient'; +import { connect, NetConnectOpts, Socket } from 'net'; +import { LanguageClient, LanguageClientOptions, ServerOptions, StreamInfo } from 'vscode-languageclient'; import { legend, semanticTokensProvider } from './highlight'; import * as config from './config'; import { registerBuildCommands } from './build_commands'; import * as checkDependencies from './check_dependencies'; let client: LanguageClient; +let socket: Socket export async function activate(context: vscode.ExtensionContext) { @@ -108,5 +110,12 @@ export function deactivate(): Thenable | undefined { if (!client) { return undefined; } - return client.stop(); + if (socket) { + // Don't call client.stop when we are connected via socket for development. + // That call will end the LS server, leading to a bad dev experience. + socket.end(); + return; + } else { + return client.stop(); + } }