Skip to content

Commit b58d85e

Browse files
author
Andrew Hall
authored
Disable all LSP Server toasts (#7624)
Fixes microsoft/vscode-dotnettools#722 dotnet/razor#10541
1 parent cfb38c8 commit b58d85e

7 files changed

+60
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
- Debug from .csproj and .sln [#5876](https://github.com/dotnet/vscode-csharp/issues/5876)
55

66
# Latest
7+
* Suppress recoverable errors from razor LSP (PR: [#7624](https://github.com/dotnet/vscode-csharp/pull/7624))
8+
* NOTE: this can be re-enabled by setting `razor.languageServer.suppressLspErrorToasts = false`
79
* Update Roslyn to 4.13.0-1.24501.3 (PR: [#7618](https://github.com/dotnet/vscode-csharp/pull/7618))
810
* Fix issue loading analyzers when using EnforceCodeStyleInBuild (PR: [#75250](https://github.com/dotnet/roslyn/pull/75250))
911
* Update Razor to 9.0.0-preview.24480.1 (PR: [#7618](https://github.com/dotnet/vscode-csharp/pull/7618))

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,11 @@
15361536
"default": false,
15371537
"description": "%configuration.razor.languageServer.forceRuntimeCodeGeneration%",
15381538
"order": 90
1539+
},
1540+
"razor.languageServer.suppressLspErrorToasts": {
1541+
"type": "boolean",
1542+
"default": true,
1543+
"description": "%configuration.razor.languageServer.suppressLspErrorToasts%"
15391544
}
15401545
}
15411546
},

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
"configuration.razor.languageServer.debug": "Specifies whether to wait for debug attach when launching the language server.",
128128
"configuration.razor.server.trace": "Specifies the logging level to use for the Razor server.",
129129
"configuration.razor.languageServer.forceRuntimeCodeGeneration": "(EXPERIMENTAL) Enable combined design time/runtime code generation for Razor files",
130+
"configuration.razor.languageServer.suppressLspErrorToasts": "Suppresses error toasts from showing up if the server encounters a recoverable error.",
130131
"debuggers.coreclr.configurationSnippets.label.console-local": ".NET: Launch Executable file (Console)",
131132
"debuggers.coreclr.configurationSnippets.label.web-local": ".NET: Launch Executable file (Web)",
132133
"debuggers.coreclr.configurationSnippets.label.attach-local": ".NET: Attach to a .NET process",

src/razor/src/razorLanguageClient.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import {
7+
CancellationToken,
8+
LanguageClient,
9+
LanguageClientOptions,
10+
MessageSignature,
11+
ServerOptions,
12+
} from 'vscode-languageclient/node';
13+
import { RazorLanguageServerOptions } from './razorLanguageServerOptions';
14+
15+
export class RazorLanguageClient extends LanguageClient {
16+
razorOptions: RazorLanguageServerOptions;
17+
18+
constructor(
19+
id: string,
20+
name: string,
21+
serverOptions: ServerOptions,
22+
clientOptions: LanguageClientOptions,
23+
razorOptions: RazorLanguageServerOptions,
24+
forceDebug?: boolean
25+
) {
26+
super(id, name, serverOptions, clientOptions, forceDebug);
27+
this.razorOptions = razorOptions;
28+
}
29+
30+
override handleFailedRequest<T>(
31+
type: MessageSignature,
32+
token: CancellationToken | undefined,
33+
error: any,
34+
defaultValue: T,
35+
showNotification?: boolean
36+
) {
37+
if (this.razorOptions.suppressErrorToasts) {
38+
return super.handleFailedRequest(type, token, error, defaultValue, false);
39+
}
40+
41+
return super.handleFailedRequest(type, token, error, defaultValue, showNotification);
42+
}
43+
}

src/razor/src/razorLanguageServerClient.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { EventEmitter } from 'events';
88
import * as vscode from 'vscode';
99
import { RequestHandler, RequestType } from 'vscode-jsonrpc';
1010
import { GenericNotificationHandler, InitializeResult, LanguageClientOptions, State } from 'vscode-languageclient';
11-
import { LanguageClient, ServerOptions } from 'vscode-languageclient/node';
11+
import { ServerOptions } from 'vscode-languageclient/node';
1212
import { RazorLanguage } from './razorLanguage';
1313
import { RazorLanguageServerOptions } from './razorLanguageServerOptions';
1414
import { resolveRazorLanguageServerOptions } from './razorLanguageServerOptionsResolver';
@@ -18,6 +18,7 @@ import { TelemetryReporter as RazorTelemetryReporter } from './telemetryReporter
1818
import TelemetryReporter from '@vscode/extension-telemetry';
1919
import { randomUUID } from 'crypto';
2020
import { showErrorMessage } from '../../shared/observers/utils/showMessage';
21+
import { RazorLanguageClient } from './razorLanguageClient';
2122

2223
const events = {
2324
ServerStop: 'ServerStop',
@@ -26,7 +27,7 @@ const events = {
2627
export class RazorLanguageServerClient implements vscode.Disposable {
2728
private clientOptions!: LanguageClientOptions;
2829
private serverOptions!: ServerOptions;
29-
private client!: LanguageClient;
30+
private client!: RazorLanguageClient;
3031
private onStartListeners: Array<() => Promise<any>> = [];
3132
private onStartedListeners: Array<() => Promise<any>> = [];
3233
private eventBus: EventEmitter;
@@ -299,11 +300,12 @@ export class RazorLanguageServerClient implements vscode.Disposable {
299300

300301
this.serverOptions = childProcess;
301302

302-
this.client = new LanguageClient(
303+
this.client = new RazorLanguageClient(
303304
'razorLanguageServer',
304305
'Razor Language Server',
305306
this.serverOptions,
306-
this.clientOptions
307+
this.clientOptions,
308+
options
307309
);
308310
}
309311
}

src/razor/src/razorLanguageServerOptions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export interface RazorLanguageServerOptions {
1313
logLevel: LogLevel;
1414
usingOmniSharp: boolean;
1515
forceRuntimeCodeGeneration: boolean;
16+
suppressErrorToasts: boolean;
1617
}

src/razor/src/razorLanguageServerOptionsResolver.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export function resolveRazorLanguageServerOptions(
2525
const usingOmniSharp =
2626
!getCSharpDevKit() && vscodeApi.workspace.getConfiguration().get<boolean>('dotnet.server.useOmnisharp');
2727
const forceRuntimeCodeGeneration = serverConfig.get<boolean>('forceRuntimeCodeGeneration');
28+
const suppressErrorToasts = serverConfig.get<boolean>('suppressLspErrorToasts');
2829

2930
return {
3031
serverPath: languageServerExecutablePath,
@@ -33,6 +34,7 @@ export function resolveRazorLanguageServerOptions(
3334
outputChannel: logger.outputChannel,
3435
usingOmniSharp,
3536
forceRuntimeCodeGeneration,
37+
suppressErrorToasts,
3638
} as RazorLanguageServerOptions;
3739
}
3840

0 commit comments

Comments
 (0)