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

Commit

Permalink
added go.inferGopath. Similar to GoSublime's use_gs_gopath (#762)
Browse files Browse the repository at this point in the history
* added go.inferGopath. Similar to GoSublime's use_gs_gopath. see #757

* fix lint problems
  • Loading branch information
codmajik authored and ramya-rao-a committed Feb 3, 2017
1 parent b8ca94f commit 94960c7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ The following Visual Studio Code settings are available for the Go extension. T
"go.formatFlags": [],
"go.goroot": "/usr/local/go",
"go.gopath": "/Users/lukeh/go",
"go.inferGopath": false,
"go.gocodeAutoBuild": false
}
```
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@
"default": false,
"description": "Complete functions with their parameter signature"
},
"go.inferGopath": {
"type": "boolean",
"default": false,
"description": "use workspace root to find appropriate GOPATH"
},
"go.gopath": {
"type": [
"string",
Expand Down
11 changes: 11 additions & 0 deletions src/goInstallTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ export function updateGoPathGoRootFromConfig() {
if (gopath) {
process.env['GOPATH'] = gopath.replace(/\${workspaceRoot}/g, vscode.workspace.rootPath);
}

let inferGoPath = vscode.workspace.getConfiguration('go')['inferGopath'];
if (inferGoPath) {
let dirs = vscode.workspace.rootPath.toLowerCase().split(path.sep);
// find src directory closest to workspace root
let srcIdx = dirs.lastIndexOf('src');

if (srcIdx > 0) {
process.env['GOPATH'] = vscode.workspace.rootPath.substr(0, dirs.slice(0, srcIdx).join(path.sep).length);
}
}
}

export function setupGoPathAndOfferToInstallTools() {
Expand Down

0 comments on commit 94960c7

Please sign in to comment.