@@ -20,6 +20,7 @@ import { getBinPath, resolvePath } from './util';
2020import { CommandFactory } from './commands' ;
2121import { GoExtensionContext } from './context' ;
2222import { TelemetryKey , telemetryReporter } from './goTelemetry' ;
23+ import { getFromGlobalState , updateGlobalState } from './stateUtils' ;
2324
2425const generatedWord = 'Generated ' ;
2526
@@ -208,6 +209,43 @@ interface Config {
208209 isTestFile ?: boolean ;
209210}
210211
212+ /**
213+ * THIRD_PARTY_TOOL_SUGGESTION_PREFIX_KEY is the prefix of key storing whether
214+ * we have suggested user to provide feedbacks about gopls's source code actions.
215+ */
216+ export const THIRD_PARTY_TOOL_SUGGESTION_PREFIX_KEY = 'third-party-tool-suggested-' ;
217+
218+ export async function promptForFeedback ( tool : string ) {
219+ let command : string ;
220+ if ( tool === 'gotests' ) {
221+ command = 'add_test' ;
222+ } else if ( tool === 'gomodifytags' ) {
223+ command = 'modify_tags' ;
224+ } else {
225+ return ;
226+ }
227+
228+ const suggested : Boolean = getFromGlobalState ( THIRD_PARTY_TOOL_SUGGESTION_PREFIX_KEY + tool , false ) ;
229+ if ( suggested ) {
230+ return ;
231+ }
232+ updateGlobalState ( THIRD_PARTY_TOOL_SUGGESTION_PREFIX_KEY + tool , true ) ;
233+
234+ const message = `It looks like you are using legacy tool "${ tool } ". Do you know gopls offers the same functionality builtin to gopls through the context menu, the command palette, or source code actions? Would you be willing to tell us why you choose the legacy tools, so that we can improve gopls?` ;
235+
236+ const selected = await vscode . window . showWarningMessage ( message , 'Yes' , 'No' ) ;
237+
238+ if ( selected === undefined || selected === 'No' ) {
239+ return ;
240+ }
241+
242+ await vscode . env . openExternal (
243+ vscode . Uri . parse (
244+ `https://github.com/golang/go/issues/new?title=x%2Ftools%2Fgopls%3A+${ command } +source+code+action+feedback&labels=tools,gopls`
245+ )
246+ ) ;
247+ }
248+
211249function generateTests (
212250 ctx : vscode . ExtensionContext ,
213251 goCtx : GoExtensionContext ,
@@ -217,6 +255,10 @@ function generateTests(
217255 return new Promise < boolean > ( ( resolve , reject ) => {
218256 telemetryReporter . add ( TelemetryKey . TOOL_USAGE_GOTESTS , 1 ) ;
219257
258+ if ( goConfig . get ( 'useLanguageServer' ) === 'true' ) {
259+ promptForFeedback ( 'gotests' ) ;
260+ }
261+
220262 const cmd = getBinPath ( 'gotests' ) ;
221263 let args = [ '-w' ] ;
222264 const goGenerateTestsFlags : string [ ] = goConfig [ 'generateTestsFlags' ] || [ ] ;
0 commit comments