Skip to content

Commit b660f86

Browse files
committed
Simplify LSP server initialization and improve failure experience
1 parent 2756ca3 commit b660f86

3 files changed

Lines changed: 76 additions & 227 deletions

File tree

l10n/bundle.l10n.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,6 @@
157157
"Do not load any": "Do not load any",
158158
"Reload C# Extension": "Reload C# Extension",
159159
"Detected change in telemetry settings. These will not take effect until the language server is restarted, would you like to restart?": "Detected change in telemetry settings. These will not take effect until the language server is restarted, would you like to restart?",
160-
"IntelliCode features will not be available, {0} failed to activate.": "IntelliCode features will not be available, {0} failed to activate.",
161-
"Go to output": "Go to output",
162-
"Suppress notification": "Suppress notification",
163160
"Restore {0}": "Restore {0}",
164161
"Restore already in progress": "Restore already in progress",
165162
"Select context": "Select context",

src/lsptoolshost/server/roslynLanguageClient.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import * as vscode from 'vscode';
67
import { CancellationToken, MessageSignature } from 'vscode-jsonrpc';
7-
import { LanguageClient } from 'vscode-languageclient/node';
8-
import { LanguageClientOptions, ServerOptions } from 'vscode-languageclient';
8+
import { LanguageClient, ServerOptions } from 'vscode-languageclient/node';
9+
import { LanguageClientOptions } from 'vscode-languageclient';
910
import CompositeDisposable from '../../compositeDisposable';
1011
import { IDisposable } from '../../disposable';
1112
import { languageServerOptions } from '../../shared/options';
1213
import { RoslynLspErrorCodes } from './roslynProtocol';
14+
import { showErrorMessageWithOptions } from '../../shared/observers/utils/showMessage';
1315

1416
/**
1517
* Implementation of the base LanguageClient type that allows for additional items to be disposed of
@@ -57,7 +59,32 @@ export class RoslynLanguageClient extends LanguageClient {
5759
if (languageServerOptions.suppressLspErrorToasts) {
5860
return super.handleFailedRequest(type, token, error, defaultValue, false);
5961
}
60-
return super.handleFailedRequest(type, token, error, defaultValue, showNotification);
62+
// test.
63+
// todo - we need to somehow prevent this from showing toasts for errors when the server crashes, since we already get them below too.
64+
return super.handleFailedRequest(type, token, error, defaultValue, false);
65+
}
66+
67+
override error(message: string, data?: any, showNotification?: boolean | 'force'): void {
68+
// Show custom error toast with report issue command button, the base does not include this.
69+
// Here we only show toasts for critical errors (when showNotification is 'force').
70+
71+
// todo - this needs to de-duplicate errors. on crashes we can get multiple errors (slightly diff messages, esp if stopping the server failed).
72+
// @ts-expect-error dddddd
73+
const s = this.state;
74+
if (showNotification === 'force') {
75+
showErrorMessageWithOptions(
76+
vscode,
77+
message,
78+
{ modal: false },
79+
{
80+
title: 'Report Issue',
81+
command: 'csharp.reportIssue',
82+
}
83+
);
84+
showNotification = false; // prevent the base class from showing another toast with the same message.
85+
}
86+
87+
super.error(message, data, showNotification);
6188
}
6289

6390
/**

0 commit comments

Comments
 (0)