Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable all LSP Server toasts #7624

Merged
merged 4 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
- Debug from .csproj and .sln [#5876](https://github.com/dotnet/vscode-csharp/issues/5876)

# Latest
* Suppress recoverable errors from razor LSP (PR: [#7624](https://github.com/dotnet/vscode-csharp/pull/7624))
* NOTE: this can be re-enabled by setting `razor.languageServer.suppressLspErrorToasts = false`
* Update Roslyn to 4.13.0-1.24501.3 (PR: [#7618](https://github.com/dotnet/vscode-csharp/pull/7618))
* Fix issue loading analyzers when using EnforceCodeStyleInBuild (PR: [#75250](https://github.com/dotnet/roslyn/pull/75250))
* Update Razor to 9.0.0-preview.24480.1 (PR: [#7618](https://github.com/dotnet/vscode-csharp/pull/7618))
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,11 @@
"default": false,
"description": "%configuration.razor.languageServer.forceRuntimeCodeGeneration%",
"order": 90
},
"razor.languageServer.suppressLspErrorToasts": {
"type": "boolean",
"default": true,
"description": "%configuration.razor.languageServer.suppressLspErrorToasts%"
}
}
},
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"configuration.razor.languageServer.debug": "Specifies whether to wait for debug attach when launching the language server.",
"configuration.razor.server.trace": "Specifies the logging level to use for the Razor server.",
"configuration.razor.languageServer.forceRuntimeCodeGeneration": "(EXPERIMENTAL) Enable combined design time/runtime code generation for Razor files",
"configuration.razor.languageServer.suppressLspErrorToasts": "Suppresses error toasts from showing up if the server encounters a recoverable error.",
"debuggers.coreclr.configurationSnippets.label.console-local": ".NET: Launch Executable file (Console)",
"debuggers.coreclr.configurationSnippets.label.web-local": ".NET: Launch Executable file (Web)",
"debuggers.coreclr.configurationSnippets.label.attach-local": ".NET: Attach to a .NET process",
Expand Down
43 changes: 43 additions & 0 deletions src/razor/src/razorLanguageClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import {
CancellationToken,
LanguageClient,
LanguageClientOptions,
MessageSignature,
ServerOptions,
} from 'vscode-languageclient/node';
import { RazorLanguageServerOptions } from './razorLanguageServerOptions';

export class RazorLanguageClient extends LanguageClient {
razorOptions: RazorLanguageServerOptions;

constructor(
id: string,
name: string,
serverOptions: ServerOptions,
clientOptions: LanguageClientOptions,
razorOptions: RazorLanguageServerOptions,
forceDebug?: boolean
) {
super(id, name, serverOptions, clientOptions, forceDebug);
this.razorOptions = razorOptions;
}

override handleFailedRequest<T>(
type: MessageSignature,
token: CancellationToken | undefined,
error: any,
defaultValue: T,
showNotification?: boolean
) {
if (this.razorOptions.suppressErrorToasts) {
return super.handleFailedRequest(type, token, error, defaultValue, false);
}

return super.handleFailedRequest(type, token, error, defaultValue, showNotification);
}
}
10 changes: 6 additions & 4 deletions src/razor/src/razorLanguageServerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { EventEmitter } from 'events';
import * as vscode from 'vscode';
import { RequestHandler, RequestType } from 'vscode-jsonrpc';
import { GenericNotificationHandler, InitializeResult, LanguageClientOptions, State } from 'vscode-languageclient';
import { LanguageClient, ServerOptions } from 'vscode-languageclient/node';
import { ServerOptions } from 'vscode-languageclient/node';
import { RazorLanguage } from './razorLanguage';
import { RazorLanguageServerOptions } from './razorLanguageServerOptions';
import { resolveRazorLanguageServerOptions } from './razorLanguageServerOptionsResolver';
Expand All @@ -18,6 +18,7 @@ import { TelemetryReporter as RazorTelemetryReporter } from './telemetryReporter
import TelemetryReporter from '@vscode/extension-telemetry';
import { randomUUID } from 'crypto';
import { showErrorMessage } from '../../shared/observers/utils/showMessage';
import { RazorLanguageClient } from './razorLanguageClient';

const events = {
ServerStop: 'ServerStop',
Expand All @@ -26,7 +27,7 @@ const events = {
export class RazorLanguageServerClient implements vscode.Disposable {
private clientOptions!: LanguageClientOptions;
private serverOptions!: ServerOptions;
private client!: LanguageClient;
private client!: RazorLanguageClient;
private onStartListeners: Array<() => Promise<any>> = [];
private onStartedListeners: Array<() => Promise<any>> = [];
private eventBus: EventEmitter;
Expand Down Expand Up @@ -299,11 +300,12 @@ export class RazorLanguageServerClient implements vscode.Disposable {

this.serverOptions = childProcess;

this.client = new LanguageClient(
this.client = new RazorLanguageClient(
'razorLanguageServer',
'Razor Language Server',
this.serverOptions,
this.clientOptions
this.clientOptions,
options
);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/razor/src/razorLanguageServerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export interface RazorLanguageServerOptions {
logLevel: LogLevel;
usingOmniSharp: boolean;
forceRuntimeCodeGeneration: boolean;
suppressErrorToasts: boolean;
}
2 changes: 2 additions & 0 deletions src/razor/src/razorLanguageServerOptionsResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export function resolveRazorLanguageServerOptions(
const usingOmniSharp =
!getCSharpDevKit() && vscodeApi.workspace.getConfiguration().get<boolean>('dotnet.server.useOmnisharp');
const forceRuntimeCodeGeneration = serverConfig.get<boolean>('forceRuntimeCodeGeneration');
const suppressErrorToasts = serverConfig.get<boolean>('suppressLspErrorToasts');

return {
serverPath: languageServerExecutablePath,
Expand All @@ -33,6 +34,7 @@ export function resolveRazorLanguageServerOptions(
outputChannel: logger.outputChannel,
usingOmniSharp,
forceRuntimeCodeGeneration,
suppressErrorToasts,
} as RazorLanguageServerOptions;
}

Expand Down
Loading