diff --git a/src/goInstallTools.ts b/src/goInstallTools.ts index cc4344448..40f78f869 100644 --- a/src/goInstallTools.ts +++ b/src/goInstallTools.ts @@ -227,23 +227,20 @@ export function updateGoPathGoRootFromConfig(): Promise { } } - if (process.env['GOPATH'] && process.env['GOROOT']) { + if (process.env['GOPATH']) { return Promise.resolve(); } - // If GOPATH and GOROOT are still not set, then use the ones from `go env` + // If GOPATH is still not set, then use the one from `go env` let goRuntimePath = getGoRuntimePath(); return new Promise((resolve, reject) => { - cp.execFile(goRuntimePath, ['env', 'GOROOT', 'GOPATH'], (err, stdout, stderr) => { + cp.execFile(goRuntimePath, ['env', 'GOPATH'], (err, stdout, stderr) => { if (err) { return reject(); } let envOutput = stdout.split('\n'); - if (!process.env['GOROOT'] && envOutput[0].trim()) { - process.env['GOROOT'] = envOutput[0].trim(); - } - if (!process.env['GOPATH'] && envOutput[1].trim()) { - process.env['GOPATH'] = envOutput[1].trim(); + if (!process.env['GOPATH'] && envOutput[0].trim()) { + process.env['GOPATH'] = envOutput[0].trim(); } return resolve(); }); diff --git a/src/goPath.ts b/src/goPath.ts index 4373192dd..1546ef54b 100644 --- a/src/goPath.ts +++ b/src/goPath.ts @@ -82,6 +82,12 @@ export function getGoRuntimePath(): string { let pathparts = (process.env.PATH).split(path.delimiter); runtimePathCache = pathparts.map(dir => path.join(dir, correctBinNameGo)).filter(candidate => fileExists(candidate))[0]; } + if (!runtimePathCache) { + let defaultPathForGo = process.platform === 'win32' ? 'C:\\Go\\bin\\go.exe' : '/usr/local/go/bin/go'; + if (fileExists(defaultPathForGo)) { + runtimePathCache = defaultPathForGo; + } + } return runtimePathCache; }