From 6111321fda4ec6c469e5fa78aba9bd2c31dffd51 Mon Sep 17 00:00:00 2001 From: Evan Reichard Date: Sat, 2 May 2026 00:42:44 -0400 Subject: [PATCH] fix(extension): suppress warnings for unsupported file types and missing binaries Move pickServer() into the try-catch in runLsp() so UnsupportedExtensionError is caught directly. Add message-based fallback in both runLsp() and runDiagnostics() to handle daemon-wrapped errors that come through as plain Error instances rather than the original typed exception. This eliminates spurious 'No LSP server registered' warnings during auto-check after edit/write on files without LSP support (e.g. .md, .txt, .sh). --- index.ts | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/index.ts b/index.ts index ec1cb91..939bd64 100644 --- a/index.ts +++ b/index.ts @@ -244,26 +244,37 @@ async function runLsp( method: string, params: Record, ): Promise { - // Check Disabled - The server for this file is blocked; bail before - // touching the daemon so other pi instances sharing it are unaffected. - const server = pickServer(filePath); - if (disabledServers.has(server.id)) { - throw new Error( - `LSP server "${server.id}" is disabled. Use /lsp-enable ${server.id} to re-enable.`, - ); - } try { + // Check Disabled - The server for this file is blocked; bail before + // touching the daemon so other pi instances sharing it are unaffected. + const server = pickServer(filePath); + if (disabledServers.has(server.id)) { + throw new Error( + `LSP server "${server.id}" is disabled. Use /lsp-enable ${server.id} to re-enable.`, + ); + } return await daemonRequest(filePath, method, params); } catch (error) { if (isExpectedError(error)) { return undefined; } + // Daemon-wrapped errors (plain Error with expected message) are also + // expected — the daemon catches pickServer() throws and returns them + // as string error messages. + if ( + error instanceof Error && + (error.message.includes("No LSP server registered") || + error.message.includes("not found on PATH")) + ) { + return undefined; + } throw error; } } // Run LSP Diagnostics - Diagnostics arrive as a notification, so the -// daemon has a dedicated op that waits for the next publish. +// daemon has a dedicated op that waits for the next publish. Expected +// errors (unsupported file type, missing binary) are suppressed. async function runDiagnostics(filePath: string): Promise { try { return await daemonDiagnostics(filePath, 1500); @@ -271,6 +282,16 @@ async function runDiagnostics(filePath: string): Promise { if (isExpectedError(error)) { return undefined; } + // Daemon-wrapped errors (plain Error with expected message) are also + // expected — the daemon catches pickServer() throws and returns them + // as string error messages. + if ( + error instanceof Error && + (error.message.includes("No LSP server registered") || + error.message.includes("not found on PATH")) + ) { + return undefined; + } throw error; } }