Skip to content

Commit 4d3c647

Browse files
authored
Merge pull request #7106 from dibarbet/allow_toast_suppression
Add temporary option to allow suppression of recoverable LSP error toasts
2 parents e33ad19 + 2d9a3f3 commit 4d3c647

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,11 @@
17031703
"default": null,
17041704
"description": "%configuration.dotnet.server.crashDumpPath%"
17051705
},
1706+
"dotnet.server.suppressLspErrorToasts": {
1707+
"type": "boolean",
1708+
"default": false,
1709+
"description": "%configuration.dotnet.server.suppressLspErrorToasts%"
1710+
},
17061711
"dotnet.projects.binaryLogPath": {
17071712
"scope": "machine-overridable",
17081713
"type": "string",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"configuration.dotnet.server.trace": "Sets the logging level for the language server",
3232
"configuration.dotnet.server.extensionPaths": "Override for path to language server --extension arguments",
3333
"configuration.dotnet.server.crashDumpPath": "Sets a folder path where crash dumps are written to if the language server crashes. Must be writeable by the user.",
34+
"configuration.dotnet.server.suppressLspErrorToasts": "Suppresses error toasts from showing up if the server encounters a recoverable error.",
3435
"configuration.dotnet.projects.enableAutomaticRestore": "Enables automatic NuGet restore if the extension detects assets are missing.",
3536
"configuration.dotnet.preferCSharpExtension": "Forces projects to load with the C# extension only. This can be useful when using legacy project types that are not supported by C# Dev Kit. (Requires window reload)",
3637
"configuration.dotnet.implementType.insertionBehavior": "The insertion location of properties, events, and methods When implement interface or abstract class.",

src/lsptoolshost/roslynLanguageClient.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient/node';
6+
import {
7+
CancellationToken,
8+
LanguageClient,
9+
LanguageClientOptions,
10+
MessageSignature,
11+
ServerOptions,
12+
} from 'vscode-languageclient/node';
713
import CompositeDisposable from '../compositeDisposable';
814
import { IDisposable } from '../disposable';
15+
import { languageServerOptions } from '../shared/options';
916

1017
/**
1118
* Implementation of the base LanguageClient type that allows for additional items to be disposed of
@@ -31,6 +38,27 @@ export class RoslynLanguageClient extends LanguageClient {
3138
return super.dispose(timeout);
3239
}
3340

41+
override handleFailedRequest<T>(
42+
type: MessageSignature,
43+
token: CancellationToken | undefined,
44+
error: any,
45+
defaultValue: T,
46+
showNotification?: boolean
47+
) {
48+
// Temporarily allow LSP error toasts to be suppressed if configured.
49+
// There are a few architectural issues preventing us from solving some of the underlying problems,
50+
// for example Razor cohosting to fix text mismatch issues and unification of serialization libraries
51+
// to fix URI identification issues. Once resolved, we should remove this option.
52+
//
53+
// See also https://github.com/microsoft/vscode-dotnettools/issues/722
54+
// https://github.com/dotnet/vscode-csharp/issues/6973
55+
// https://github.com/microsoft/vscode-languageserver-node/issues/1449
56+
if (languageServerOptions.suppressLspErrorToasts) {
57+
return super.handleFailedRequest(type, token, error, defaultValue, false);
58+
}
59+
return super.handleFailedRequest(type, token, error, defaultValue, showNotification);
60+
}
61+
3462
/**
3563
* Adds a disposable that should be disposed of when the LanguageClient instance gets disposed.
3664
*/

src/shared/options.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export interface LanguageServerOptions {
7777
readonly crashDumpPath: string | undefined;
7878
readonly analyzerDiagnosticScope: string;
7979
readonly compilerDiagnosticScope: string;
80+
readonly suppressLspErrorToasts: boolean;
8081
}
8182

8283
export interface RazorOptions {
@@ -397,6 +398,9 @@ class LanguageServerOptionsImpl implements LanguageServerOptions {
397398
public get compilerDiagnosticScope() {
398399
return readOption<string>('dotnet.backgroundAnalysis.compilerDiagnosticsScope', 'openFiles');
399400
}
401+
public get suppressLspErrorToasts() {
402+
return readOption<boolean>('dotnet.server.suppressLspErrorToasts', false);
403+
}
400404
}
401405

402406
class RazorOptionsImpl implements RazorOptions {

0 commit comments

Comments
 (0)