Skip to content

Commit 99369b6

Browse files
committed
src/language/goLanguageServer: remove redundant error popups from custom error handler
From vscode-languageclient v8.0.x (LSP 3.17), the language client reports the start errors specially and surfaces them as user visible popups regardless revealOutputChannelOn setting. Thus, our error popups are no longer necessary. Remove this. When an error occurs during initialization, the connection to the server shuts down which triggers the close handler. Previously, we suggested gopls issue report from both initializationFailedHandler and errorHandler.closed handler. That now results in two gopls issue report suggestions. Instead, stash the initialization failure error, and handle the suggestion prompt from one place. Note - in case of initializtion error, there is no point of retrying 5 times. We also explicitly set the error & connection close handlers messages to empty when requesting for continue/restart action, which will suppresses the default error message popups. While we are here, we improve the go status bar's language server state report by updating it when the language server connection close is obeserved. Updates microsoft/vscode-languageserver-node#1011 Fixes #2300 Change-Id: I8b20cf11ebb61ab474950440fc46ff23f7b0b826 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/414457 Reviewed-by: Jamal Carvalho <[email protected]> TryBot-Result: kokoro <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]>
1 parent 4dd972e commit 99369b6

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

src/commands/startLanguageServer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const startLanguageServer: CommandFactory = (ctx, goCtx) => {
3939
}
4040

4141
const unlock = await languageServerStartMutex.lock();
42+
goCtx.latestConfig = cfg;
4243
try {
4344
if (reason === RestartReason.MANUAL) {
4445
await suggestGoplsIssueReport(
@@ -52,6 +53,7 @@ export const startLanguageServer: CommandFactory = (ctx, goCtx) => {
5253
if (goCtx.languageClient) {
5354
await stopLanguageClient(goCtx);
5455
}
56+
updateStatus(goCtx, goConfig, false);
5557

5658
// Before starting the language server, make sure to deregister any
5759
// currently registered language providers.
@@ -100,7 +102,6 @@ export const startLanguageServer: CommandFactory = (ctx, goCtx) => {
100102
console.log(msg);
101103
goCtx.serverOutputChannel?.append(msg);
102104
} finally {
103-
goCtx.latestConfig = cfg;
104105
unlock();
105106
}
106107
};

src/language/goLanguageServer.ts

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import { ProvideFoldingRangeSignature } from 'vscode-languageclient/lib/common/f
5656
import { daysBetween, getStateConfig, maybePromptForGoplsSurvey, timeDay, timeMinute } from '../goSurvey';
5757
import { maybePromptForDeveloperSurvey } from '../goDeveloperSurvey';
5858
import { CommandFactory } from '../commands';
59+
import { updateLanguageServerIconGoStatusBar } from '../goStatus';
5960

6061
export interface LanguageServerConfig {
6162
serverName: string;
@@ -360,6 +361,11 @@ export async function buildLanguageClient(
360361
{ language: 'gotmpl', scheme: 'file' }
361362
];
362363

364+
// when initialization is failed after the connection is established,
365+
// we want to handle the connection close error case specially. Capture the error
366+
// in initializationFailedHandler and handle it in the connectionCloseHandler.
367+
let initializationError: WebRequest.ResponseError<InitializeError> | undefined = undefined;
368+
363369
const c = new LanguageClient(
364370
'go', // id
365371
cfg.serverName, // name e.g. gopls
@@ -381,41 +387,56 @@ export async function buildLanguageClient(
381387
traceOutputChannel: cfg.traceOutputChannel,
382388
revealOutputChannelOn: RevealOutputChannelOn.Never,
383389
initializationFailedHandler: (error: WebRequest.ResponseError<InitializeError>): boolean => {
384-
vscode.window.showErrorMessage(
385-
`The language server is not able to serve any features. Initialization failed: ${error}. `
386-
);
387-
suggestGoplsIssueReport(
388-
goCtx,
389-
'The gopls server failed to initialize',
390-
errorKind.initializationFailure,
391-
error
392-
);
390+
initializationError = error;
393391
return false;
394392
},
395393
errorHandler: {
396394
error: (error: Error, message: Message, count: number) => {
397395
// Allow 5 crashes before shutdown.
398396
if (count < 5) {
399-
return { action: ErrorAction.Continue };
397+
return {
398+
message: '', // suppresses error popups
399+
action: ErrorAction.Continue
400+
};
400401
}
401-
vscode.window.showErrorMessage(
402-
`Error communicating with the language server: ${error}: ${message}.`
403-
);
404-
return { action: ErrorAction.Shutdown };
402+
return {
403+
action: ErrorAction.Shutdown
404+
};
405405
},
406406
closed: () => {
407+
if (initializationError !== undefined) {
408+
suggestGoplsIssueReport(
409+
goCtx,
410+
'The gopls server failed to initialize.',
411+
errorKind.initializationFailure,
412+
initializationError
413+
);
414+
initializationError = undefined;
415+
// In case of initialization failure, do not try to restart.
416+
return {
417+
message: 'The gopls server failed to initialize.',
418+
action: CloseAction.DoNotRestart
419+
};
420+
}
421+
407422
// Allow 5 crashes before shutdown.
408423
const { crashCount = 0 } = goCtx;
409424
goCtx.crashCount = crashCount + 1;
410425
if (goCtx.crashCount < 5) {
411-
return { action: CloseAction.Restart };
426+
return {
427+
message: '', // suppresses error popups
428+
action: CloseAction.Restart
429+
};
412430
}
413431
suggestGoplsIssueReport(
414432
goCtx,
415433
'The connection to gopls has been closed. The gopls server may have crashed.',
416434
errorKind.crash
417435
);
418-
return { action: CloseAction.DoNotRestart };
436+
updateLanguageServerIconGoStatusBar(false, true);
437+
return {
438+
action: CloseAction.DoNotRestart
439+
};
419440
}
420441
},
421442
middleware: {

0 commit comments

Comments
 (0)