diff --git a/index.ts b/index.ts index 6a7bc05..e450662 100644 --- a/index.ts +++ b/index.ts @@ -334,6 +334,18 @@ function pickDiagnosticServers(filePath: string): string[] { .map((s) => s.id); } +// Timeout Wrapper - Rejects a promise after the given number of milliseconds. +// Used to prevent async hooks from blocking pi indefinitely. +function withTimeout(promise: Promise, ms: number): Promise { + return new Promise((resolve, reject) => { + const timer = setTimeout(() => reject(new Error(`Timeout after ${ms}ms`)), ms); + promise.then( + (value) => { clearTimeout(timer); resolve(value); }, + (reason) => { clearTimeout(timer); reject(reason); }, + ); + }); +} + // Run LSP Diagnostics - Fans out to all matching servers in a single // daemon call. Returns the grouped result map or undefined if no servers. async function runDiagnostics(filePath: string): Promise { @@ -557,8 +569,9 @@ export default function (pi: ExtensionAPI) { const absolutePath = path.resolve(ctx.cwd, filePath); try { - // Run LSP diagnostics - const result = await runDiagnostics(absolutePath); + // Run LSP diagnostics with timeout - Prevent the auto-check hook from + // blocking pi if the daemon or LSP server is slow or unresponsive. + const result = await withTimeout(runDiagnostics(absolutePath), 3000); const formatted = formatDiagnostics(result, 10); // Only send a message if there are actual diagnostics diff --git a/server.ts b/server.ts index 38679fa..7c3a6ea 100644 --- a/server.ts +++ b/server.ts @@ -100,12 +100,44 @@ export const servers: ServerConfig[] = [ }, { id: "vscode-html-language-server", - match: ["html", "css", "jsonl", "jsonc", "json"], + match: ["html"], command: "vscode-html-language-server", args: ["--stdio"], rootMarkers: ["package.json"], languageId: "html", }, + { + id: "vscode-css-language-server", + match: ["css", "scss", "less"], + command: "vscode-css-language-server", + args: ["--stdio"], + rootMarkers: ["package.json"], + languageId: "css", + }, + { + id: "vscode-json-language-server", + match: ["json", "jsonc", "jsonl"], + command: "vscode-json-language-server", + args: ["--stdio"], + rootMarkers: ["package.json"], + languageId: "json", + }, + { + id: "bash-language-server", + match: ["sh", "bash"], + command: "bash-language-server", + args: ["start"], + rootMarkers: [".git"], + languageId: "shellscript", + }, + { + id: "sqls", + match: ["sql"], + command: "sqls", + args: [], + rootMarkers: [".git"], + languageId: "sql", + }, { id: "nil", match: ["nix"],