From c014233987fd703be7436cd3d87a66c8470c9826 Mon Sep 17 00:00:00 2001 From: Steve Dunham Date: Fri, 27 Mar 2026 20:20:08 -0700 Subject: [PATCH] debug lsp crashes --- newt-vscode-lsp/src/lsp.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/newt-vscode-lsp/src/lsp.ts b/newt-vscode-lsp/src/lsp.ts index 040a067..1a7a467 100644 --- a/newt-vscode-lsp/src/lsp.ts +++ b/newt-vscode-lsp/src/lsp.ts @@ -16,6 +16,8 @@ import { Location, TextDocumentIdentifier, } from "vscode-languageserver/node"; +import fs from 'node:fs'; +import path from 'node:path'; import { TextDocument } from "vscode-languageserver-textdocument"; const connection = createConnection(ProposedFeatures.all); @@ -70,16 +72,18 @@ async function runChange() { console.log('STALE result not sent for', uri) } } + } catch (e) { + console.error(e); } finally { running = false; } } - documents.onDidChangeContent(async (change) => { console.log('DIDCHANGE', change.document.uri) const uri = change.document.uri; const text = change.document.getText(); // update/invalidate happens now, check happens on quiesce. + writeCache(path.basename(uri), text); LSP_updateFile(uri, text); addChange(change.document); }); @@ -138,6 +142,21 @@ connection.onInitialize((_params: InitializeParams): InitializeResult => ({ }, })); +function writeCache(fn: string, content: string) { + const home = process.env.HOME; + if (!home) return; + const dname = path.join(home, '.cache/newt-lsp'); + const fname = path.join(dname, fn); + try { + fs.mkdirSync(dname, {recursive: true}); + } catch (e) { + } + try { + fs.writeFileSync(fname, content, 'utf8'); + } catch (e) { + console.error(e); + } +} documents.listen(connection); connection.listen(); console.log('STARTED')