From b87ba57819a3dfa458b34c9cec9362c7028adf6e Mon Sep 17 00:00:00 2001 From: Dax Raad Date: Mon, 26 May 2025 14:52:38 -0400 Subject: shutdown --- js/src/lsp/client.ts | 5 +++++ js/src/lsp/index.ts | 36 ++++++++++++++++++++++-------------- js/src/lsp/language.ts | 2 +- 3 files changed, 28 insertions(+), 15 deletions(-) (limited to 'js/src/lsp') diff --git a/js/src/lsp/client.ts b/js/src/lsp/client.ts index f07b21c7f..0c9f9d06c 100644 --- a/js/src/lsp/client.ts +++ b/js/src/lsp/client.ts @@ -178,6 +178,11 @@ export namespace LSPClient { }), ]); }, + async shutdown() { + log.info("shutting down"); + connection.end(); + connection.dispose(); + }, }; return result; diff --git a/js/src/lsp/index.ts b/js/src/lsp/index.ts index f20a15e70..80503fb1f 100644 --- a/js/src/lsp/index.ts +++ b/js/src/lsp/index.ts @@ -5,22 +5,30 @@ import { LSPClient } from "./client"; export namespace LSP { const log = Log.create({ service: "lsp" }); - const state = App.state("lsp", async () => { - const clients = new Map(); + const state = App.state( + "lsp", + async () => { + const clients = new Map(); - // QUESTION: how lazy should lsp auto discovery be? should it not initialize until a file is opened? - clients.set( - "typescript", - await LSPClient.create({ - cmd: ["bun", "x", "typescript-language-server", "--stdio"], - }), - ); + // QUESTION: how lazy should lsp auto discovery be? should it not initialize until a file is opened? + clients.set( + "typescript", + await LSPClient.create({ + cmd: ["bun", "x", "typescript-language-server", "--stdio"], + }), + ); - return { - clients, - diagnostics: new Map(), - }; - }); + return { + clients, + diagnostics: new Map(), + }; + }, + async (state) => { + for (const client of state.clients.values()) { + await client.shutdown(); + } + }, + ); export async function run( input: (client: LSPClient.Info) => Promise, diff --git a/js/src/lsp/language.ts b/js/src/lsp/language.ts index 964ebc803..14b32edfa 100644 --- a/js/src/lsp/language.ts +++ b/js/src/lsp/language.ts @@ -1,4 +1,4 @@ -export const LANGUAGE_EXTENSIONS = { +export const LANGUAGE_EXTENSIONS: Record = { ".abap": "abap", ".bat": "bat", ".bib": "bibtex", -- cgit v1.2.3