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).
This commit is contained in:
2026-05-02 00:42:44 -04:00
parent 9b863168ff
commit 6111321fda

View File

@@ -244,6 +244,7 @@ async function runLsp(
method: string, method: string,
params: Record<string, unknown>, params: Record<string, unknown>,
): Promise<unknown> { ): Promise<unknown> {
try {
// Check Disabled - The server for this file is blocked; bail before // Check Disabled - The server for this file is blocked; bail before
// touching the daemon so other pi instances sharing it are unaffected. // touching the daemon so other pi instances sharing it are unaffected.
const server = pickServer(filePath); const server = pickServer(filePath);
@@ -252,18 +253,28 @@ async function runLsp(
`LSP server "${server.id}" is disabled. Use /lsp-enable ${server.id} to re-enable.`, `LSP server "${server.id}" is disabled. Use /lsp-enable ${server.id} to re-enable.`,
); );
} }
try {
return await daemonRequest(filePath, method, params); return await daemonRequest(filePath, method, params);
} catch (error) { } catch (error) {
if (isExpectedError(error)) { if (isExpectedError(error)) {
return undefined; 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; throw error;
} }
} }
// Run LSP Diagnostics - Diagnostics arrive as a notification, so the // 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<unknown> { async function runDiagnostics(filePath: string): Promise<unknown> {
try { try {
return await daemonDiagnostics(filePath, 1500); return await daemonDiagnostics(filePath, 1500);
@@ -271,6 +282,16 @@ async function runDiagnostics(filePath: string): Promise<unknown> {
if (isExpectedError(error)) { if (isExpectedError(error)) {
return undefined; 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; throw error;
} }
} }