Skip to content

Commit

Permalink
src/goLanguageServer: show command failure error messages from gopls
Browse files Browse the repository at this point in the history
When a command execution fails, gopls returns the error details
an error. The LSP client throws an error when receiving the error
response and logs the error details in the server output channel.
But, the error details aren't propagated to VSCode's renderer
process so lost.

Handle the error from the middleware, give an option for user
to see the gopls server trace, and do not rethrow the error
to prevent VSCode from opening another error message popup.

Verified manually. Not sure what kind of automated testing
we want here.

Fixes #1237

Change-Id: Ie4cea6337775bab00125fed95266eb4b81423dca
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/300389
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
  • Loading branch information
hyangah committed Mar 10, 2021
1 parent fb5bc5b commit 658a52b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/goLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
ConfigurationParams,
ConfigurationRequest,
ErrorAction,
ExecuteCommandSignature,
HandleDiagnosticsSignature,
InitializeError,
Message,
Expand Down Expand Up @@ -500,6 +501,20 @@ export async function buildLanguageClient(cfg: BuildLanguageClientOption): Promi
}
},
middleware: {
executeCommand: async (command: string, args: any[], next: ExecuteCommandSignature) => {
try {
return await next(command, args);
} catch (e) {
const answer = await vscode.window.showErrorMessage(
`Command '${command}' failed: ${e}.`,
'Show Trace'
);
if (answer === 'Show Trace') {
serverOutputChannel.show();
}
return null;
}
},
provideFoldingRanges: async (
doc: vscode.TextDocument,
context: FoldingContext,
Expand Down

0 comments on commit 658a52b

Please sign in to comment.