Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
Make tools re-compiling warnings scoped by toolsGopath (#1589)
Browse files Browse the repository at this point in the history
* Make tools re-compiling warnings scoped by toolsGopath

When switching between workspaces with different goroot and toolsGopath
settings, the editor is suggesting that re-compiling tools is required
because the GOROOT state is global and not toolsGopath-aware.

This makes the global context a map keyed on toolsGopath.

* Apply pascal case to interface name

* Minor fixes
  • Loading branch information
FiloSottile authored and Vlad Barosan committed Mar 28, 2019
1 parent 8de993a commit b597ae8
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions src/goMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,36 +66,45 @@ export function activate(ctx: vscode.ExtensionContext): void {
let useLangServer = vscode.workspace.getConfiguration('go')['useLanguageServer'];
setGlobalState(ctx.globalState);

updateGoPathGoRootFromConfig().then(() => {
updateGoPathGoRootFromConfig().then(async () => {
const updateToolsCmdText = 'Update tools';
const prevGoroot = ctx.globalState.get('goroot');
const currentGoroot = process.env['GOROOT'];
if (prevGoroot !== currentGoroot && prevGoroot) {
vscode.window.showInformationMessage('Your goroot is different than before, a few Go tools may need recompiling', updateToolsCmdText).then(selected => {
interface GoInfo {
goroot: string;
version: string;
}
const toolsGoInfo: { [id: string]: GoInfo; } = ctx.globalState.get('toolsGoInfo') || {};
const toolsGopath = getToolsGopath() || getCurrentGoPath();
if (!toolsGoInfo[toolsGopath]) {
toolsGoInfo[toolsGopath] = { goroot: null, version: null };
}
const prevGoroot = toolsGoInfo[toolsGopath].goroot;
const currentGoroot: string = process.env['GOROOT'];
if (prevGoroot && prevGoroot !== currentGoroot) {
vscode.window.showInformationMessage(`Your current goroot (${currentGoroot}) is different than before (${prevGoroot}), a few Go tools may need recompiling`, updateToolsCmdText).then(selected => {
if (selected === updateToolsCmdText) {
installAllTools(true);
}
});
} else {
getGoVersion().then(currentVersion => {
if (currentVersion) {
const prevVersion = ctx.globalState.get('goVersion');
const currVersionString = `${currentVersion.major}.${currentVersion.minor}`;

if (prevVersion !== currVersionString) {
if (prevVersion) {
vscode.window.showInformationMessage('Your Go version is different than before, few Go tools may need re-compiling', updateToolsCmdText).then(selected => {
if (selected === updateToolsCmdText) {
installAllTools(true);
}
});
}
ctx.globalState.update('goVersion', currVersionString);
const currentVersion = await getGoVersion();
if (currentVersion) {
const prevVersion = toolsGoInfo[toolsGopath].version;
const currVersionString = `${currentVersion.major}.${currentVersion.minor}`;

if (prevVersion !== currVersionString) {
if (prevVersion) {
vscode.window.showInformationMessage('Your Go version is different than before, few Go tools may need re-compiling', updateToolsCmdText).then(selected => {
if (selected === updateToolsCmdText) {
installAllTools(true);
}
});
}
toolsGoInfo[toolsGopath].version = currVersionString;
}
});
}
}
ctx.globalState.update('goroot', currentGoroot);
toolsGoInfo[toolsGopath].goroot = currentGoroot;
ctx.globalState.update('toolsGoInfo', toolsGoInfo);

offerToInstallTools();
if (checkLanguageServer()) {
Expand Down

0 comments on commit b597ae8

Please sign in to comment.