Skip to content

Commit

Permalink
Auto merge of #15846 - jprochazk:disable-error-notification, r=Veykril
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
bors committed Nov 24, 2023
2 parents 8733728 + 9c8727e commit fec3828
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,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);
}
}

0 comments on commit fec3828

Please sign in to comment.