Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

editor/code: add option to suppress internal error notifications #15846

Merged
merged 4 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,11 @@
"default": true,
"type": "boolean"
},
"rust-analyzer.showRequestFailedErrorNotification": {
"markdownDescription": "Whether to show error notifications for failing requests.",
"default": true,
"type": "boolean"
},
"rust-analyzer.showDependenciesExplorer": {
"markdownDescription": "Whether to show the dependencies view.",
"default": true,
Expand Down
3 changes: 2 additions & 1 deletion editors/code/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { type Config, prepareVSCodeConfig } from "./config";
import { randomUUID } from "crypto";
import { sep as pathSeparator } from "path";
import { unwrapUndefinable } from "./undefinable";
import { RaLanguageClient } from "./lang_client";

export interface Env {
[name: string]: string;
Expand Down Expand Up @@ -363,7 +364,7 @@ export async function createClient(
},
};

const client = new lc.LanguageClient(
const client = new RaLanguageClient(
"rust-analyzer",
"Rust Analyzer Language Server",
serverOptions,
Expand Down
26 changes: 26 additions & 0 deletions editors/code/src/lang_client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as lc from "vscode-languageclient/node";
import * as vscode from "vscode";

export class RaLanguageClient extends lc.LanguageClient {
override handleFailedRequest<T>(
type: lc.MessageSignature,
token: vscode.CancellationToken | undefined,
error: any,
defaultValue: T,
showNotification?: boolean | undefined,
): T {
const showError = vscode.workspace
.getConfiguration("rust-analyzer")
.get("showRequestFailedErrorNotification");
if (
!showError &&
error instanceof lc.ResponseError &&
error.code === lc.ErrorCodes.InternalError
) {
// Don't show notification for internal errors, these are emitted by r-a when a request fails.
showNotification = false;
}

return super.handleFailedRequest(type, token, error, defaultValue, showNotification);
}
}