Skip to content

Commit 7cfdb98

Browse files
committed
Add temporary option to allow suppression of recoverable LSP error toasts
1 parent 6a9cce5 commit 7cfdb98

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,11 @@
16661666
"default": null,
16671667
"description": "%configuration.dotnet.server.crashDumpPath%"
16681668
},
1669+
"dotnet.server.suppressLspErrorToasts": {
1670+
"type": "boolean",
1671+
"default": false,
1672+
"description": "%configuration.dotnet.server.suppressLspErrorToasts%"
1673+
},
16691674
"dotnet.projects.binaryLogPath": {
16701675
"scope": "machine-overridable",
16711676
"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: 31 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
@@ -14,6 +21,8 @@ import { IDisposable } from '../disposable';
1421
export class RoslynLanguageClient extends LanguageClient {
1522
private readonly _disposables: CompositeDisposable;
1623

24+
//private readonly Map<
25+
1726
constructor(
1827
id: string,
1928
name: string,
@@ -31,6 +40,27 @@ export class RoslynLanguageClient extends LanguageClient {
3140
return super.dispose(timeout);
3241
}
3342

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

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)