Skip to content

Commit 73c670e

Browse files
h9jianggopherbot
authored andcommitted
extension/src: send one time prompt to user who uses third party tools
For golang/go#1652 Change-Id: I5c802ee5ab9ef4bbc54c2a0877dcff2b5dfa4ca2 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/713962 Reviewed-by: Madeline Kalil <mkalil@google.com> Auto-Submit: Hongxiang Jiang <hxjiang@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 6fc8296 commit 73c670e

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

extension/src/goGenerateTests.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { getBinPath, resolvePath } from './util';
2020
import { CommandFactory } from './commands';
2121
import { GoExtensionContext } from './context';
2222
import { TelemetryKey, telemetryReporter } from './goTelemetry';
23+
import { getFromGlobalState, updateGlobalState } from './stateUtils';
2324

2425
const 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+
211249
function 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'] || [];

extension/src/goModifytags.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { toolExecutionEnvironment } from './goEnv';
1515
import { promptForMissingTool, promptForUpdatingTool } from './goInstallTools';
1616
import { byteOffsetAt, getBinPath, getFileArchive } from './util';
1717
import { TelemetryKey, telemetryReporter } from './goTelemetry';
18+
import { promptForFeedback } from './goGenerateTests';
1819

1920
export const COMMAND = 'gopls.modify_tags';
2021

@@ -241,6 +242,11 @@ async function getTagsAndOptions(config: GoTagsConfig): Promise<(string | undefi
241242

242243
async function runGomodifytags(args: string[]) {
243244
telemetryReporter.add(TelemetryKey.TOOL_USAGE_GOMODIFYTAGS, 1);
245+
246+
if (getGoConfig().get('useLanguageServer') === 'true') {
247+
promptForFeedback('gomodifytags');
248+
}
249+
244250
const editor = vscode.window.activeTextEditor;
245251
if (!editor) {
246252
return;

0 commit comments

Comments
 (0)