Skip to content

Commit d7f9578

Browse files
committed
src/language/goLanguageServer: restore gopls opt-out survey prompt
triggered by gopls setting change. (revert of https://go-review.googlesource.com/c/vscode-go/+/387656) While we are here, remove the intermediate prompt that asks users to re-enable gopls for users who disabled gopls. It was added a year ago while making gopls the default, in order to ask users to return to use gopls. It served well for the purpose and it's time to retire. For #2120 Change-Id: Ic5be2e0838f721e51caeb51dfcdeb78da6c59466 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/394776 Trust: Hyang-Ah Hana Kim <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Jamal Carvalho <[email protected]> TryBot-Result: kokoro <[email protected]>
1 parent e694981 commit d7f9578

File tree

2 files changed

+39
-67
lines changed

2 files changed

+39
-67
lines changed

src/language/goLanguageServer.ts

+11-50
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,6 @@ function scheduleGoplsSuggestions() {
254254
if (cfg.serverName !== '' && cfg.serverName !== 'gopls') {
255255
return;
256256
}
257-
// Prompt the user to enable gopls and record what actions they took.
258-
await promptAboutGoplsOptOut();
259257
// Check if the language server has now been enabled, and if so,
260258
// it will be installed below.
261259
cfg = buildLanguageServerConfig(getGoConfig());
@@ -285,8 +283,8 @@ function scheduleGoplsSuggestions() {
285283
setTimeout(survey, 30 * timeMinute);
286284
}
287285

288-
// Ask users to enable gopls. If they still don't want it, ask to fill out opt-out survey with the probability.
289-
export async function promptAboutGoplsOptOut(probability = 0.5) {
286+
// Ask users to fill out opt-out survey.
287+
export async function promptAboutGoplsOptOut() {
290288
// Check if the configuration is set in the workspace.
291289
const useLanguageServer = getGoConfig().inspect('useLanguageServer');
292290
const workspace = useLanguageServer.workspaceFolderValue === false || useLanguageServer.workspaceValue === false;
@@ -301,51 +299,10 @@ export async function promptAboutGoplsOptOut(probability = 0.5) {
301299
return cfg;
302300
}
303301
cfg.lastDatePrompted = new Date();
304-
305-
const selected = await vscode.window.showInformationMessage(
306-
`We noticed that you have disabled the language server.
307-
It has [stabilized](https://blog.golang.org/gopls-vscode-go) and is now enabled by default in this extension.
308-
Would you like to enable it now?`,
309-
{ title: 'Enable' },
310-
{ title: 'Not now' },
311-
{ title: 'Never' }
302+
await promptForGoplsOptOutSurvey(
303+
cfg,
304+
"It looks like you've disabled the Go language server. Would you be willing to tell us why you've disabled it, so that we can improve it?"
312305
);
313-
if (!selected) {
314-
return cfg;
315-
}
316-
switch (selected.title) {
317-
case 'Enable':
318-
{
319-
// Change the user's Go configuration to enable the language server.
320-
// Remove the setting entirely, since it's on by default now.
321-
const goConfig = getGoConfig();
322-
await goConfig.update('useLanguageServer', undefined, vscode.ConfigurationTarget.Global);
323-
if (goConfig.inspect('useLanguageServer').workspaceValue === false) {
324-
await goConfig.update('useLanguageServer', undefined, vscode.ConfigurationTarget.Workspace);
325-
}
326-
if (goConfig.inspect('useLanguageServer').workspaceFolderValue === false) {
327-
await goConfig.update(
328-
'useLanguageServer',
329-
undefined,
330-
vscode.ConfigurationTarget.WorkspaceFolder
331-
);
332-
}
333-
cfg.prompt = false;
334-
}
335-
break;
336-
case 'Not now':
337-
cfg.prompt = true;
338-
break;
339-
case 'Never':
340-
cfg.prompt = false;
341-
if (Math.random() < probability) {
342-
await promptForGoplsOptOutSurvey(
343-
cfg,
344-
'No problem. Would you be willing to tell us why you have opted out of the language server?'
345-
);
346-
}
347-
break;
348-
}
349306
return cfg;
350307
};
351308
cfg = await promptFn();
@@ -390,12 +347,12 @@ export const getGoplsOptOutConfig = (workspace: boolean): GoplsOptOutConfig => {
390347
return getStateConfig(goplsOptOutConfigKey, workspace) as GoplsOptOutConfig;
391348
};
392349

393-
function flushGoplsOptOutConfig(cfg: GoplsOptOutConfig, workspace: boolean) {
350+
export const flushGoplsOptOutConfig = (cfg: GoplsOptOutConfig, workspace: boolean) => {
394351
if (workspace) {
395352
updateWorkspaceState(goplsOptOutConfigKey, JSON.stringify(cfg));
396353
}
397354
updateGlobalState(goplsOptOutConfigKey, JSON.stringify(cfg));
398-
}
355+
};
399356

400357
async function startLanguageServer(ctx: vscode.ExtensionContext, config: LanguageServerConfig): Promise<boolean> {
401358
// If the client has already been started, make sure to clear existing
@@ -911,6 +868,10 @@ export async function watchLanguageServerConfiguration(e: vscode.ConfigurationCh
911868
) {
912869
restartLanguageServer('config change');
913870
}
871+
872+
if (e.affectsConfiguration('go.useLanguageServer') && getGoConfig()['useLanguageServer'] === false) {
873+
promptAboutGoplsOptOut();
874+
}
914875
}
915876

916877
export function buildLanguageServerConfig(goConfig: vscode.WorkspaceConfiguration): LanguageServerConfig {

test/gopls/survey.test.ts

+28-17
Original file line numberDiff line numberDiff line change
@@ -197,31 +197,42 @@ suite('gopls opt out', () => {
197197
sandbox.restore();
198198
});
199199

200-
// testConfig, choice, probability, wantCount
201-
const testCases: [goLanguageServer.GoplsOptOutConfig, string, number, number][] = [
200+
const today = new Date();
201+
const yesterday = new Date(today.valueOf() - 1000 * 60 * 60 * 24);
202+
203+
// testConfig, choice, wantCount
204+
const testCases: [goLanguageServer.GoplsOptOutConfig, string, number][] = [
202205
// No saved config, different choices in the first dialog box.
203-
[{}, 'Enable', undefined, 1],
204-
[{}, 'Not now', undefined, 1],
205-
[{}, 'Never', 1, 2],
206-
[{}, 'Never', 0, 1],
207-
[{}, 'Never', undefined, -1], // Non-deterministic. Skip callCount check.
208-
// Saved config, doesn't matter what the user chooses.
209-
[{ prompt: false }, '', undefined, 0],
210-
[{ prompt: false, lastDatePrompted: new Date() }, '', undefined, 0],
211-
[{ prompt: true }, '', undefined, 1],
212-
[{ prompt: true, lastDatePrompted: new Date() }, '', undefined, 0]
206+
[{}, 'Yes', 1],
207+
[{}, 'No', 1],
208+
[{}, '', 1],
209+
[{ lastDatePrompted: new Date('2020-04-02') }, '', 1],
210+
[{ lastDatePrompted: yesterday }, '', 0],
211+
[{ prompt: false }, '', 0],
212+
[{ prompt: false, lastDatePrompted: new Date('2020-04-02') }, '', 0],
213+
[{ prompt: false, lastDatePrompted: yesterday }, '', 0],
214+
[{ prompt: true }, '', 1],
215+
[{ prompt: true, lastDatePrompted: new Date('2020-04-02') }, 'Yes', 1],
216+
[{ prompt: true, lastDatePrompted: yesterday }, '', 0]
213217
];
214218

215-
testCases.map(async ([testConfig, choice, probability, wantCount], i) => {
219+
testCases.map(async ([testConfig, choice, wantCount], i) => {
216220
test(`opt out: ${i}`, async () => {
217221
const stub = sandbox.stub(vscode.window, 'showInformationMessage').resolves({ title: choice });
218222
const getGoplsOptOutConfigStub = sandbox.stub(goLanguageServer, 'getGoplsOptOutConfig').returns(testConfig);
223+
const flushGoplsOptOutConfigStub = sandbox.stub(goLanguageServer, 'flushGoplsOptOutConfig');
219224

220-
await goLanguageServer.promptAboutGoplsOptOut(probability);
221-
if (wantCount >= 0) {
222-
assert.strictEqual(stub.callCount, wantCount);
223-
}
225+
await goLanguageServer.promptAboutGoplsOptOut();
226+
assert.strictEqual(stub.callCount, wantCount, 'unexpected call count');
224227
sandbox.assert.called(getGoplsOptOutConfigStub);
228+
sandbox.assert.calledOnce(flushGoplsOptOutConfigStub);
229+
const got = flushGoplsOptOutConfigStub.getCall(0).args[0];
230+
if (choice === 'Yes') assert.strictEqual(got.prompt, false, 'unexpected prompt config stored');
231+
if (wantCount > 0)
232+
assert(
233+
got.lastDatePrompted >= today,
234+
`unexpected lastDatePrompted: ${JSON.stringify(got.lastDatePrompted)}`
235+
);
225236
});
226237
});
227238
});

0 commit comments

Comments
 (0)