Improvements to GOPATH and PATH search for Go tools
This commit is contained in:
Родитель
bf61793b34
Коммит
0f20bc67df
|
@ -102,9 +102,14 @@ The extension uses the following tools, installed in the current GOPATH. If any
|
||||||
- goreturns: `go get -u -v sourcegraph.com/sqs/goreturns`
|
- goreturns: `go get -u -v sourcegraph.com/sqs/goreturns`
|
||||||
- gorename: `go get -u -v golang.org/x/tools/cmd/gorename`
|
- gorename: `go get -u -v golang.org/x/tools/cmd/gorename`
|
||||||
|
|
||||||
To install them just paste and run
|
To install them just paste and run:
|
||||||
```bash
|
```bash
|
||||||
go get -u -v github.com/nsf/gocode github.com/rogpeppe/godef github.com/golang/lint/golint github.com/lukehoban/go-find-references sourcegraph.com/sqs/goreturns golang.org/x/tools/cmd/gorename
|
go get -u -v github.com/nsf/gocode
|
||||||
|
go get -u -v github.com/rogpeppe/godef
|
||||||
|
go get -u -v github.com/golang/lint/golint
|
||||||
|
go get -u -v github.com/lukehoban/go-find-references
|
||||||
|
go get -u -v sourcegraph.com/sqs/goreturns
|
||||||
|
go get -u -v golang.org/x/tools/cmd/gorename
|
||||||
```
|
```
|
||||||
|
|
||||||
And for debugging:
|
And for debugging:
|
||||||
|
|
|
@ -14,18 +14,33 @@ import { showGoStatus, hideGoStatus } from './goStatus'
|
||||||
var binPathCache : { [bin: string]: string;} = {}
|
var binPathCache : { [bin: string]: string;} = {}
|
||||||
|
|
||||||
export function getBinPath(binname) {
|
export function getBinPath(binname) {
|
||||||
binname = correctBinname(binname)
|
|
||||||
if(binPathCache[binname]) return binPathCache[binname];
|
if(binPathCache[binname]) return binPathCache[binname];
|
||||||
var workspaces = getGOPATHWorkspaces();
|
binname = correctBinname(binname);
|
||||||
var binpath: string;
|
var binpath: string;
|
||||||
|
|
||||||
|
// First search each GOPATH workspace's bin folder
|
||||||
|
var workspaces = getPathParts(process.env["GOPATH"]);
|
||||||
for(var i = 0; i < workspaces.length; i++) {
|
for(var i = 0; i < workspaces.length; i++) {
|
||||||
binpath = path.join(workspaces[i], "bin", binname);
|
binpath = path.join(workspaces[i], "bin", binname);
|
||||||
if(fs.existsSync(binpath)) {
|
if(fs.existsSync(binpath)) {
|
||||||
|
binPathCache[binname] = binpath;
|
||||||
return binpath;
|
return binpath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("Couldn't find a binary in any GOPATH workspaces: ", binname, " ", workspaces)
|
|
||||||
return path.join(process.env["GOPATH"], "bin", binname);
|
// Then search PATH parts
|
||||||
|
var pathparts = getPathParts(process.env["PATH"]);
|
||||||
|
for(var i = 0; i < pathparts.length; i++) {
|
||||||
|
binpath = path.join(pathparts[i], binname);
|
||||||
|
if(fs.existsSync(binpath)) {
|
||||||
|
binPathCache[binname] = binpath;
|
||||||
|
return binpath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Else return the binary name directly (this will likely always fail downstream)
|
||||||
|
binPathCache[binname] = binname;
|
||||||
|
return binname;
|
||||||
}
|
}
|
||||||
|
|
||||||
function correctBinname(binname) {
|
function correctBinname(binname) {
|
||||||
|
@ -35,7 +50,7 @@ function correctBinname(binname) {
|
||||||
return binname
|
return binname
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGOPATHWorkspaces() {
|
function getPathParts(path: string) {
|
||||||
var seperator : string;
|
var seperator : string;
|
||||||
switch(os.platform()) {
|
switch(os.platform()) {
|
||||||
case 'win32':
|
case 'win32':
|
||||||
|
@ -48,7 +63,7 @@ function getGOPATHWorkspaces() {
|
||||||
seperator = ':';
|
seperator = ':';
|
||||||
}
|
}
|
||||||
|
|
||||||
var parts = process.env["GOPATH"].split(seperator);
|
var parts = path.split(seperator);
|
||||||
return parts;
|
return parts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +87,7 @@ export function setupGoPathAndOfferToInstallTools() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Offer to install any missing tools
|
// Offer to install any missing tools
|
||||||
var tools = {
|
var tools: {[key:string]: string} = {
|
||||||
gorename: "golang.org/x/tools/cmd/gorename",
|
gorename: "golang.org/x/tools/cmd/gorename",
|
||||||
gocode: "github.com/nsf/gocode",
|
gocode: "github.com/nsf/gocode",
|
||||||
goreturns: "sourcegraph.com/sqs/goreturns",
|
goreturns: "sourcegraph.com/sqs/goreturns",
|
||||||
|
|
Загрузка…
Ссылка в новой задаче