in src/language/goLanguageServer.ts [156:222]
export function scheduleGoplsSuggestions(goCtx: GoExtensionContext) {
if (extensionInfo.isInCloudIDE) {
return;
}
// Some helper functions.
const usingGopls = (cfg: LanguageServerConfig): boolean => {
return cfg.enabled && cfg.serverName === 'gopls';
};
const installGopls = async (cfg: LanguageServerConfig) => {
const tool = getTool('gopls');
const versionToUpdate = await shouldUpdateLanguageServer(tool, cfg);
if (!versionToUpdate) {
return;
}
// If the user has opted in to automatic tool updates, we can update
// without prompting.
const toolsManagementConfig = getGoConfig()['toolsManagement'];
if (toolsManagementConfig && toolsManagementConfig['autoUpdate'] === true) {
if (extensionInfo.isPreview || (await okForStagedRollout(tool, versionToUpdate, hashMachineID))) {
const goVersion = await getGoVersion();
const toolVersion = { ...tool, version: versionToUpdate }; // ToolWithVersion
await installTools([toolVersion], goVersion, true);
} else {
console.log(`gopls ${versionToUpdate} is too new, try to update later`);
}
} else {
promptForUpdatingTool(tool.name, versionToUpdate);
}
};
const update = async () => {
setTimeout(update, timeDay);
let cfg = buildLanguageServerConfig(getGoConfig());
if (!usingGopls(cfg)) {
// This shouldn't happen, but if the user has a non-gopls language
// server enabled, we shouldn't prompt them to change.
if (cfg.serverName !== '' && cfg.serverName !== 'gopls') {
return;
}
// Check if the language server has now been enabled, and if so,
// it will be installed below.
cfg = buildLanguageServerConfig(getGoConfig());
if (!cfg.enabled) {
return;
}
}
await installGopls(cfg);
};
const survey = async () => {
setTimeout(survey, timeDay);
// Only prompt for the survey if the user is working on Go code.
let foundGo = false;
for (const doc of vscode.workspace.textDocuments) {
if (doc.languageId === 'go') {
foundGo = true;
}
}
if (!foundGo) {
return;
}
maybePromptForGoplsSurvey(goCtx);
maybePromptForDeveloperSurvey(goCtx);
};
setTimeout(update, 10 * timeMinute);
setTimeout(survey, 30 * timeMinute);
}