Skip to content

Commit

Permalink
src/goLanguageServer: prompt users to file an issue if they opted out
Browse files Browse the repository at this point in the history
If the user has explicitly disabled the language server when the default is set true, prompt the message, but never prompt it more often than every three months.
Currently, only enabled when the default is true, which means it's the nightly extension - guarded by isNightly from goMain.ts.

Fixes #738

Change-Id: I3f4b454a482df02feda03ca14808b147fb39a81a
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/273186
Run-TryBot: Hyang-Ah Hana Kim <[email protected]>
TryBot-Result: kokoro <[email protected]>
Trust: Hyang-Ah Hana Kim <[email protected]>
Trust: Suzy Mueller <[email protected]>
Reviewed-by: Rebecca Stambler <[email protected]>
  • Loading branch information
hyangah committed Dec 3, 2020
1 parent 49bca83 commit f379f50
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions src/goLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1114,8 +1114,8 @@ Would you be willing to fill out a quick survey about your experience with gopls

export const goplsSurveyConfig = 'goplsSurveyConfig';

function getSurveyConfig(): SurveyConfig {
const saved = getFromGlobalState(goplsSurveyConfig);
function getSurveyConfig(surveyConfigKey = goplsSurveyConfig): SurveyConfig {
const saved = getFromGlobalState(surveyConfigKey);
if (saved === undefined) {
return {};
}
Expand Down Expand Up @@ -1390,16 +1390,19 @@ export function sanitizeGoplsTrace(logs?: string): string {
}

export async function promptForLanguageServerDefaultChange(cfg: vscode.WorkspaceConfiguration) {
const promptedForLSDefaultChangeKey = `promptedForLSDefaultChange`;
if (getFromGlobalState(promptedForLSDefaultChangeKey, false)) {
return;
}

const useLanguageServer = cfg.inspect<boolean>('useLanguageServer');
if (useLanguageServer.globalValue !== undefined || useLanguageServer.workspaceValue !== undefined) {
if (!cfg['useLanguageServer']) { // ask users who explicitly disabled.
promptForLanguageServerOptOutSurvey();
}
return; // user already explicitly set the field.
}

const promptedForLSDefaultChangeKey = `promptedForLSDefaultChange`;
if (getFromGlobalState(promptedForLSDefaultChangeKey, false)) {
return;
}

const selected = await vscode.window.showInformationMessage(
`"go.useLanguageServer" is enabled by default. If you need to disable it, please configure in the settings.`,
'Open Settings', 'OK');
Expand All @@ -1410,3 +1413,36 @@ export async function promptForLanguageServerDefaultChange(cfg: vscode.Workspace
}
updateGlobalState(promptedForLSDefaultChangeKey, true);
}

// Prompt users who disabled the language server and ask to file an issue.
async function promptForLanguageServerOptOutSurvey() {
const promptedForLSOptOutSurveyKey = `promptedForLSOptOutSurvey`;
const value = getSurveyConfig(promptedForLSOptOutSurveyKey); // We use only 'prompt' and 'lastDatePrompted' fields.

if (value?.prompt === false ||
(value?.lastDatePrompted && daysBetween(value.lastDatePrompted, new Date()) < 90)) {
return;
}

value.lastDatePrompted = new Date();

const selected = await vscode.window.showInformationMessage(
`Looks like you've disabled the language server. Would you be willing to file an issue and tell us why you had to disable it?`,
'Yes', 'Not now', 'Never');
switch (selected) {
case 'Yes':
const title = 'gopls: automated issue report (opt out)';
const body = `
Please tell us why you had to disable the language server.
`;
const url = `https://github.com/golang/vscode-go/issues/new?title=${title}&labels=upstream-tools&body=${body}`;
await vscode.env.openExternal(vscode.Uri.parse(url));
break;
case 'Never':
value.prompt = false;
break;
default:
}
updateGlobalState(promptedForLSOptOutSurveyKey, JSON.stringify(value));
}

0 comments on commit f379f50

Please sign in to comment.