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

Commit

Permalink
Allow Go tools to be installed in a separate GOPATH
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Herrmann committed Jan 12, 2017
1 parent 90b7b36 commit f3a3c9c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ The extension uses the following tools, installed in the current GOPATH. If any
- guru: `go get -u -v golang.org/x/tools/cmd/guru`
- gotests: `go get -u -v github.com/cweill/gotests/...`

To install them just paste and run:
If you wish to have the extension use a separate GOPATH for its tools, set the VSCODE_GOTOOLS environment variable to the desired path.

To install the tools manually in the current GOPATH, just paste and run:
```bash
go get -u -v github.com/nsf/gocode
go get -u -v github.com/rogpeppe/godef
Expand Down
8 changes: 8 additions & 0 deletions src/goInstallTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ function installTools(goVersion: SemVersion, missing?: string[]) {
HTTPS_PROXY: httpProxy,
});
}

// If the VSCODE_GOTOOLS environment variable is set, use
// its value as the GOPATH for the "go get" child precess.
let toolsGoPath = process.env['VSCODE_GOTOOLS'];
if(toolsGoPath) {
env['GOPATH'] = toolsGoPath;
}

missing.reduce((res: Promise<string[]>, tool: string) => {
return res.then(sofar => new Promise<string[]>((resolve, reject) => {
cp.execFile(goRuntimePath, ['get', '-u', '-v', tools[tool]], { env }, (err, stdout, stderr) => {
Expand Down
8 changes: 7 additions & 1 deletion src/goPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ export function getBinPathFromEnvVar(toolName: string, envVar: string, appendBin
export function getBinPath(binname: string) {
if (binPathCache[correctBinname(binname)]) return binPathCache[correctBinname(binname)];

// First search each GOPATH workspace's bin folder
// First search VSCODE_GOTOOLS' bin folder
let pathFromToolsGoPath = getBinPathFromEnvVar(binname, 'VSCODE_GOTOOLS', true);
if (pathFromToolsGoPath) {
return pathFromToolsGoPath;
}

// Then search each GOPATH workspace's bin folder
let pathFromGoPath = getBinPathFromEnvVar(binname, 'GOPATH', true);
if (pathFromGoPath) {
return pathFromGoPath;
Expand Down

0 comments on commit f3a3c9c

Please sign in to comment.