@@ -145,10 +145,9 @@ async function startLanguageServer(ctx: vscode.ExtensionContext, config: Languag
145
145
// language server.
146
146
if ( ! restartCommand ) {
147
147
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 ) ;
152
151
restartLanguageServer ( ) ;
153
152
} ) ;
154
153
ctx . subscriptions . push ( restartCommand ) ;
@@ -197,8 +196,7 @@ async function buildLanguageClient(config: LanguageServerConfig): Promise<Langua
197
196
vscode . window . showErrorMessage (
198
197
`The language server is not able to serve any features. Initialization failed: ${ error } . `
199
198
) ;
200
- serverOutputChannel . show ( ) ;
201
- suggestGoplsIssueReport ( `The gopls server failed to initialize.` ) ;
199
+ suggestGoplsIssueReport ( `The gopls server failed to initialize.` , errorKind . initializationFailure ) ;
202
200
return false ;
203
201
} ,
204
202
errorHandler : {
@@ -218,8 +216,9 @@ async function buildLanguageClient(config: LanguageServerConfig): Promise<Langua
218
216
if ( crashCount < 5 ) {
219
217
return CloseAction . Restart ;
220
218
}
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 ) ;
223
222
return CloseAction . DoNotRestart ;
224
223
} ,
225
224
} ,
@@ -814,8 +813,23 @@ function flushSurveyConfig(cfg: SurveyConfig) {
814
813
updateGlobalState ( goplsSurveyConfig , JSON . stringify ( cfg ) ) ;
815
814
}
816
815
816
+ // errorKind refers to the different possible kinds of gopls errors.
817
+ enum errorKind {
818
+ initializationFailure ,
819
+ crash ,
820
+ manualRestart ,
821
+ }
822
+
817
823
// 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
+
819
833
if ( latestConfig . serverName !== 'gopls' ) {
820
834
return ;
821
835
}
@@ -839,15 +853,38 @@ async function suggestGoplsIssueReport(msg: string) {
839
853
const selected = await vscode . window . showInformationMessage ( `${ msg } Would you like to report a gopls issue ? ` , 'Yes' , 'Next time' , 'Never' ) ;
840
854
switch ( selected ) {
841
855
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 ) ) ;
851
888
break ;
852
889
case 'Next time' :
853
890
break ;
0 commit comments