Skip to content

Commit

Permalink
feat: add setting to suppress error notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-h-chamberlain authored and jnoortheen committed Sep 10, 2024
1 parent 739f54d commit 4913819
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
]
}
}
},
Expand Down
31 changes: 29 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
LanguageClientOptions,
LSPArray,
ConfigurationParams,
MessageSignature,
CancellationToken,
} from "vscode-languageclient";
import {
Executable,
Expand All @@ -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<T>(
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<void> {
if (!commandExistsSync(config.serverPath)) {
Expand Down Expand Up @@ -68,7 +95,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
},
};

client = new LanguageClient("nix", "Nix", serverOptions, clientOptions);
client = new Client("nix", "Nix", serverOptions, clientOptions);
client.registerProposedFeatures();
await client.start();

Expand Down
4 changes: 4 additions & 0 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export class Config {
return this.get<boolean>("enableLanguageServer", false);
}

get hiddenErrorKinds(): string[] {
return this.get("hiddenLanguageServerErrors", []);
}

get serverSettings(): LSPObject {
return this.get<LSPObject>("serverSettings", {});
}
Expand Down

0 comments on commit 4913819

Please sign in to comment.