Skip to content

Commit 93ab0f6

Browse files
committed
goLanguageServer: improve gopls error report suggestion
Our current error reporting uses `gopls bug`. Modify the issue reporting mechanism to request a stack trace and make the issue template clearer. Updates #276 Change-Id: I0720422d1d20740d0bdbe02800fa5134fc4e488f Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/240506 Reviewed-by: Hyang-Ah Hana Kim <[email protected]> (cherry picked from commit 0c6bb9e) Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/241161
1 parent 837852b commit 93ab0f6

File tree

1 file changed

+55
-18
lines changed

1 file changed

+55
-18
lines changed

src/goLanguageServer.ts

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,9 @@ async function startLanguageServer(ctx: vscode.ExtensionContext, config: Languag
145145
// language server.
146146
if (!restartCommand) {
147147
restartCommand = vscode.commands.registerCommand('go.languageserver.restart', async () => {
148-
// TODO(rstambler): Enable this behavior when gopls reaches v1.0.
149-
if (false) {
150-
await suggestGoplsIssueReport(`Looks like you're about to manually restart the language server.`);
151-
}
148+
await suggestGoplsIssueReport(
149+
`Looks like you're about to manually restart the language server.`,
150+
errorKind.manualRestart);
152151
restartLanguageServer();
153152
});
154153
ctx.subscriptions.push(restartCommand);
@@ -197,8 +196,7 @@ async function buildLanguageClient(config: LanguageServerConfig): Promise<Langua
197196
vscode.window.showErrorMessage(
198197
`The language server is not able to serve any features. Initialization failed: ${error}. `
199198
);
200-
serverOutputChannel.show();
201-
suggestGoplsIssueReport(`The gopls server failed to initialize.`);
199+
suggestGoplsIssueReport(`The gopls server failed to initialize.`, errorKind.initializationFailure);
202200
return false;
203201
},
204202
errorHandler: {
@@ -218,8 +216,9 @@ async function buildLanguageClient(config: LanguageServerConfig): Promise<Langua
218216
if (crashCount < 5) {
219217
return CloseAction.Restart;
220218
}
221-
serverOutputChannel.show();
222-
suggestGoplsIssueReport(`The connection to gopls has been closed. The gopls server may have crashed.`);
219+
suggestGoplsIssueReport(
220+
`The connection to gopls has been closed. The gopls server may have crashed.`,
221+
errorKind.crash);
223222
return CloseAction.DoNotRestart;
224223
},
225224
},
@@ -814,8 +813,23 @@ function flushSurveyConfig(cfg: SurveyConfig) {
814813
updateGlobalState(goplsSurveyConfig, JSON.stringify(cfg));
815814
}
816815

816+
// errorKind refers to the different possible kinds of gopls errors.
817+
enum errorKind {
818+
initializationFailure,
819+
crash,
820+
manualRestart,
821+
}
822+
817823
// suggestGoplsIssueReport prompts users to file an issue with gopls.
818-
async function suggestGoplsIssueReport(msg: string) {
824+
async function suggestGoplsIssueReport(msg: string, reason: errorKind) {
825+
// Don't prompt users who manually restart to file issues until gopls/v1.0.
826+
if (reason === errorKind.manualRestart) {
827+
return;
828+
}
829+
830+
// Show the user the output channel content to alert them to the issue.
831+
serverOutputChannel.show();
832+
819833
if (latestConfig.serverName !== 'gopls') {
820834
return;
821835
}
@@ -839,15 +853,38 @@ async function suggestGoplsIssueReport(msg: string) {
839853
const selected = await vscode.window.showInformationMessage(`${msg} Would you like to report a gopls issue ? `, 'Yes', 'Next time', 'Never');
840854
switch (selected) {
841855
case 'Yes':
842-
// Run the `gopls bug` command directly for now. When
843-
// https://github.com/golang/go/issues/38942 is
844-
// resolved, we'll be able to do this through the
845-
// language client.
846-
847-
// Wait for the command to finish before restarting the
848-
// server, but don't bother handling errors.
849-
const execFile = util.promisify(cp.execFile);
850-
await execFile(latestConfig.path, ['bug'], { env: toolExecutionEnvironment() });
856+
// Prefill an issue title and report.
857+
let errKind: string;
858+
switch (reason) {
859+
case errorKind.crash:
860+
errKind = 'crash';
861+
break;
862+
case errorKind.initializationFailure:
863+
errKind = 'initialization';
864+
break;
865+
}
866+
const title = `gopls: automated issue report (${errKind})`;
867+
const body = `ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.
868+
869+
Describe what you observed.
870+
871+
<ANSWER HERE>
872+
873+
Please attach the stack trace from the crash.
874+
A window with the error message should have popped up in the lower half of your screen.
875+
Please copy the stack trace from that window and paste it in this issue.
876+
877+
<PASTE STACK TRACE HERE>
878+
879+
OPTIONAL: If you would like to share more information, you can attach your complete gopls logs.
880+
881+
NOTE: THESE MAY CONTAIN SENSITIVE INFORMATION ABOUT YOUR CODEBASE.
882+
DO NOT SHARE LOGS IF YOU ARE WORKING IN A PRIVATE REPOSITORY.
883+
884+
<OPTIONAL: ATTACH LOGS HERE>
885+
`;
886+
const url = `https://github.com/golang/vscode-go/issues/new?title=${title}&labels=upstream-tools&body=${body}`;
887+
await vscode.env.openExternal(vscode.Uri.parse(url));
851888
break;
852889
case 'Next time':
853890
break;

0 commit comments

Comments
 (0)