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:
39
index.ts
39
index.ts
@@ -244,26 +244,37 @@ async function runLsp(
|
|||||||
method: string,
|
method: string,
|
||||||
params: Record<string, unknown>,
|
params: Record<string, unknown>,
|
||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
// 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 {
|
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);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user