Skip to content

Commit

Permalink
Merge pull request #7106 from dibarbet/allow_toast_suppression
Browse files Browse the repository at this point in the history
Add temporary option to allow suppression of recoverable LSP error toasts
  • Loading branch information
dibarbet authored May 8, 2024
2 parents e33ad19 + 2d9a3f3 commit 4d3c647
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,11 @@
"default": null,
"description": "%configuration.dotnet.server.crashDumpPath%"
},
"dotnet.server.suppressLspErrorToasts": {
"type": "boolean",
"default": false,
"description": "%configuration.dotnet.server.suppressLspErrorToasts%"
},
"dotnet.projects.binaryLogPath": {
"scope": "machine-overridable",
"type": "string",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"configuration.dotnet.server.trace": "Sets the logging level for the language server",
"configuration.dotnet.server.extensionPaths": "Override for path to language server --extension arguments",
"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.",
"configuration.dotnet.server.suppressLspErrorToasts": "Suppresses error toasts from showing up if the server encounters a recoverable error.",
"configuration.dotnet.projects.enableAutomaticRestore": "Enables automatic NuGet restore if the extension detects assets are missing.",
"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)",
"configuration.dotnet.implementType.insertionBehavior": "The insertion location of properties, events, and methods When implement interface or abstract class.",
Expand Down
30 changes: 29 additions & 1 deletion src/lsptoolshost/roslynLanguageClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient/node';
import {
CancellationToken,
LanguageClient,
LanguageClientOptions,
MessageSignature,
ServerOptions,
} from 'vscode-languageclient/node';
import CompositeDisposable from '../compositeDisposable';
import { IDisposable } from '../disposable';
import { languageServerOptions } from '../shared/options';

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

override handleFailedRequest<T>(
type: MessageSignature,
token: CancellationToken | undefined,
error: any,
defaultValue: T,
showNotification?: boolean
) {
// Temporarily allow LSP error toasts to be suppressed if configured.
// There are a few architectural issues preventing us from solving some of the underlying problems,
// for example Razor cohosting to fix text mismatch issues and unification of serialization libraries
// to fix URI identification issues. Once resolved, we should remove this option.
//
// See also https://github.com/microsoft/vscode-dotnettools/issues/722
// https://github.com/dotnet/vscode-csharp/issues/6973
// https://github.com/microsoft/vscode-languageserver-node/issues/1449
if (languageServerOptions.suppressLspErrorToasts) {
return super.handleFailedRequest(type, token, error, defaultValue, false);
}
return super.handleFailedRequest(type, token, error, defaultValue, showNotification);
}

/**
* Adds a disposable that should be disposed of when the LanguageClient instance gets disposed.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/shared/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export interface LanguageServerOptions {
readonly crashDumpPath: string | undefined;
readonly analyzerDiagnosticScope: string;
readonly compilerDiagnosticScope: string;
readonly suppressLspErrorToasts: boolean;
}

export interface RazorOptions {
Expand Down Expand Up @@ -397,6 +398,9 @@ class LanguageServerOptionsImpl implements LanguageServerOptions {
public get compilerDiagnosticScope() {
return readOption<string>('dotnet.backgroundAnalysis.compilerDiagnosticsScope', 'openFiles');
}
public get suppressLspErrorToasts() {
return readOption<boolean>('dotnet.server.suppressLspErrorToasts', false);
}
}

class RazorOptionsImpl implements RazorOptions {
Expand Down

0 comments on commit 4d3c647

Please sign in to comment.