diff --git a/package.json b/package.json index 54d93c2..21338e7 100644 --- a/package.json +++ b/package.json @@ -95,6 +95,15 @@ "type": "object", "default": {}, "description": "Settings passed to the language server on configuration requests." + }, + "nix.hiddenLanguageServerErrors": { + "type": "array", + "items": { "type": "string" }, + "default": [], + "description": "Error notifications from the language server for these request types will be suppressed.", + "examples": [ + [ "textDocument/definition", "textDocument/documentSymbol" ] + ] } } }, diff --git a/src/client.ts b/src/client.ts index 3de296d..8be171a 100644 --- a/src/client.ts +++ b/src/client.ts @@ -5,6 +5,8 @@ import { LanguageClientOptions, LSPArray, ConfigurationParams, + MessageSignature, + CancellationToken, } from "vscode-languageclient"; import { Executable, @@ -13,8 +15,33 @@ import { } from "vscode-languageclient/node"; import { config, UriMessageItem } from "./configuration"; import { sync as commandExistsSync } from "command-exists"; +import { inspect } from "util"; -let client: LanguageClient; +class Client extends LanguageClient { + override handleFailedRequest( + type: MessageSignature, + token: CancellationToken | undefined, + error: unknown, + defaultValue: T, + showNotification?: boolean, + ): T { + if (config.hiddenErrorKinds.includes(type.method)) { + this.outputChannel.appendLine( + `Suppressing failed ${inspect(type.method)} notification`, + ); + return super.handleFailedRequest(type, token, error, defaultValue, false); + } + return super.handleFailedRequest( + type, + token, + error, + defaultValue, + showNotification, + ); + } +} + +let client: Client; export async function activate(context: ExtensionContext): Promise { if (!commandExistsSync(config.serverPath)) { @@ -68,7 +95,7 @@ export async function activate(context: ExtensionContext): Promise { }, }; - client = new LanguageClient("nix", "Nix", serverOptions, clientOptions); + client = new Client("nix", "Nix", serverOptions, clientOptions); client.registerProposedFeatures(); await client.start(); diff --git a/src/configuration.ts b/src/configuration.ts index 7c8cde4..6938ba3 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -36,6 +36,10 @@ export class Config { return this.get("enableLanguageServer", false); } + get hiddenErrorKinds(): string[] { + return this.get("hiddenLanguageServerErrors", []); + } + get serverSettings(): LSPObject { return this.get("serverSettings", {}); }