Skip to content

Commit fec3828

Browse files
committed
Auto merge of #15846 - jprochazk:disable-error-notification, r=Veykril
editor/code: add option to suppress error notifications Fixes #14193 - Added the `rust-analyzer.showRequestFailedErrorNotification` configuration option, which defaults to `true` - If `rust-analyzer.showRequestFailedErrorNotification` is set to `true`, the current behavior is preserved. - If `rust-analyzer.showRequestFailedErrorNotification` is set to `false`, no error toasts will be displayed for any of the failed requests caused by panics in r-a. This _only_ applies to events that are triggered "implicitly", such as `textDocument/hover`. To test this, you can manually introduce a panic in one of the language server LSP handlers for non-command events. I added an explicit `panic!()` in the `textDocument/hover` event handler: #### `rust-analyzer.showRequestFailedErrorNotification` set to `true` (default) [2023-11-07 17-17-48.webm](https://github.com/rust-lang/rust-analyzer/assets/1665677/d0408ab8-79d1-42cf-a4e7-94e99d9783ec) #### `rust-analyzer.showRequestFailedErrorNotification` set to `false` [2023-11-07 17-16-49.webm](https://github.com/rust-lang/rust-analyzer/assets/1665677/0496d8d0-fb53-4bc6-a279-1a47f412dbdb)
2 parents 8733728 + 9c8727e commit fec3828

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

editors/code/package.json

+5
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,11 @@
498498
"default": true,
499499
"type": "boolean"
500500
},
501+
"rust-analyzer.showRequestFailedErrorNotification": {
502+
"markdownDescription": "Whether to show error notifications for failing requests.",
503+
"default": true,
504+
"type": "boolean"
505+
},
501506
"rust-analyzer.showDependenciesExplorer": {
502507
"markdownDescription": "Whether to show the dependencies view.",
503508
"default": true,

editors/code/src/client.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { type Config, prepareVSCodeConfig } from "./config";
1010
import { randomUUID } from "crypto";
1111
import { sep as pathSeparator } from "path";
1212
import { unwrapUndefinable } from "./undefinable";
13+
import { RaLanguageClient } from "./lang_client";
1314

1415
export interface Env {
1516
[name: string]: string;
@@ -363,7 +364,7 @@ export async function createClient(
363364
},
364365
};
365366

366-
const client = new lc.LanguageClient(
367+
const client = new RaLanguageClient(
367368
"rust-analyzer",
368369
"Rust Analyzer Language Server",
369370
serverOptions,

editors/code/src/lang_client.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as lc from "vscode-languageclient/node";
2+
import * as vscode from "vscode";
3+
4+
export class RaLanguageClient extends lc.LanguageClient {
5+
override handleFailedRequest<T>(
6+
type: lc.MessageSignature,
7+
token: vscode.CancellationToken | undefined,
8+
error: any,
9+
defaultValue: T,
10+
showNotification?: boolean | undefined,
11+
): T {
12+
const showError = vscode.workspace
13+
.getConfiguration("rust-analyzer")
14+
.get("showRequestFailedErrorNotification");
15+
if (
16+
!showError &&
17+
error instanceof lc.ResponseError &&
18+
error.code === lc.ErrorCodes.InternalError
19+
) {
20+
// Don't show notification for internal errors, these are emitted by r-a when a request fails.
21+
showNotification = false;
22+
}
23+
24+
return super.handleFailedRequest(type, token, error, defaultValue, showNotification);
25+
}
26+
}

0 commit comments

Comments
 (0)