From 3e4de963a2f932a4591b037e6b5933ac5903b7e3 Mon Sep 17 00:00:00 2001 From: jprochazk <1665677+jprochazk@users.noreply.github.com> Date: Sat, 28 Oct 2023 16:34:00 +0200 Subject: [PATCH 1/4] override language client --- editors/code/src/base_client.ts | 12 ++++++++++++ editors/code/src/client.ts | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 editors/code/src/base_client.ts diff --git a/editors/code/src/base_client.ts b/editors/code/src/base_client.ts new file mode 100644 index 000000000000..085920fb6603 --- /dev/null +++ b/editors/code/src/base_client.ts @@ -0,0 +1,12 @@ +import * as lc from "vscode-languageclient/node"; + +export class RaLanguageClient extends lc.LanguageClient { + override error(message: string, data?: any, showNotification?: boolean | "force"): void { + // ignore `Request TYPE failed.` errors + if (message.startsWith("Request") && message.endsWith("failed.")) { + return; + } + + super.error(message, data, showNotification); + } +} diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index 96e888402baf..ed7066a1b7ba 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -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 "./base_client"; export interface Env { [name: string]: string; @@ -363,7 +364,7 @@ export async function createClient( }, }; - const client = new lc.LanguageClient( + const client = new RaLanguageClient( "rust-analyzer", "Rust Analyzer Language Server", serverOptions, From c566136854734ff32ddaaed107c74759a3a3862f Mon Sep 17 00:00:00 2001 From: jprochazk <1665677+jprochazk@users.noreply.github.com> Date: Tue, 7 Nov 2023 16:33:45 +0100 Subject: [PATCH 2/4] add configuration option --- editors/code/package.json | 5 +++++ editors/code/src/client.ts | 2 +- editors/code/src/{base_client.ts => lang_client.ts} | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) rename editors/code/src/{base_client.ts => lang_client.ts} (56%) diff --git a/editors/code/package.json b/editors/code/package.json index 2dde66c97006..59f89cebdeaa 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -502,6 +502,11 @@ "default": true, "type": "boolean" }, + "rust-analyzer.showRequestFailedErrorNotification": { + "markdownDescription": "Whether to show panic error notifications.", + "default": true, + "type": "boolean" + }, "rust-analyzer.showDependenciesExplorer": { "markdownDescription": "Whether to show the dependencies view.", "default": true, diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index ed7066a1b7ba..c27a446b3804 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -10,7 +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 "./base_client"; +import { RaLanguageClient } from "./lang_client"; export interface Env { [name: string]: string; diff --git a/editors/code/src/base_client.ts b/editors/code/src/lang_client.ts similarity index 56% rename from editors/code/src/base_client.ts rename to editors/code/src/lang_client.ts index 085920fb6603..e28330e6dba6 100644 --- a/editors/code/src/base_client.ts +++ b/editors/code/src/lang_client.ts @@ -1,9 +1,13 @@ import * as lc from "vscode-languageclient/node"; +import * as vscode from "vscode"; export class RaLanguageClient extends lc.LanguageClient { override error(message: string, data?: any, showNotification?: boolean | "force"): void { // ignore `Request TYPE failed.` errors - if (message.startsWith("Request") && message.endsWith("failed.")) { + const showError = vscode.workspace + .getConfiguration("rust-analyzer") + .get("showRequestFailedErrorNotification"); + if (!showError && message.startsWith("Request") && message.endsWith("failed.")) { return; } From 0d147b382f46d9f19145d03295519ca4558858af Mon Sep 17 00:00:00 2001 From: jprochazk <1665677+jprochazk@users.noreply.github.com> Date: Wed, 15 Nov 2023 12:36:08 +0100 Subject: [PATCH 3/4] detect internal error via `error.code` instead of error message --- editors/code/src/lang_client.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/editors/code/src/lang_client.ts b/editors/code/src/lang_client.ts index e28330e6dba6..09d64efc048a 100644 --- a/editors/code/src/lang_client.ts +++ b/editors/code/src/lang_client.ts @@ -2,15 +2,25 @@ import * as lc from "vscode-languageclient/node"; import * as vscode from "vscode"; export class RaLanguageClient extends lc.LanguageClient { - override error(message: string, data?: any, showNotification?: boolean | "force"): void { - // ignore `Request TYPE failed.` errors + override handleFailedRequest( + 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 && message.startsWith("Request") && message.endsWith("failed.")) { - return; + 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; } - super.error(message, data, showNotification); + return super.handleFailedRequest(type, token, error, defaultValue, showNotification); } } From 9c8727eea5ba01c87cf384b1864e7ce86f31111d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Proch=C3=A1zka?= <1665677+jprochazk@users.noreply.github.com> Date: Wed, 15 Nov 2023 12:41:54 +0100 Subject: [PATCH 4/4] Update editors/code/package.json Co-authored-by: Lukas Wirth --- editors/code/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editors/code/package.json b/editors/code/package.json index 59f89cebdeaa..850c0772f381 100644 --- a/editors/code/package.json +++ b/editors/code/package.json @@ -503,7 +503,7 @@ "type": "boolean" }, "rust-analyzer.showRequestFailedErrorNotification": { - "markdownDescription": "Whether to show panic error notifications.", + "markdownDescription": "Whether to show error notifications for failing requests.", "default": true, "type": "boolean" },