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

Commit

Permalink
Fix build when multiple workspaces are used in GOPATH
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Mar 30, 2017
1 parent 131e7a3 commit d417fd6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/goCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export function check(filename: string, goConfig: vscode.WorkspaceConfiguration)
};

let currentGoWorkspace = getCurrentGoWorkspaceFromGOPATH(cwd);
let importPath = cwd.substr(currentGoWorkspace.length + 1);
let importPath = currentGoWorkspace ? cwd.substr(currentGoWorkspace.length + 1) : cwd;

args = args.concat(['-o', tmppath, '-tags', buildTags, ...buildFlags, importPath]);
if (filename.match(/_test.go$/i)) {
Expand Down
6 changes: 3 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,16 @@ export function getBinPath(tool: string): string {

export function getCurrentGoWorkspaceFromGOPATH(currentFileDirPath: string): string {
let workspaces: string[] = process.env['GOPATH'].split(path.delimiter);
let currentWorkspace = path.join(workspaces[0], 'src');
let currentWorkspace = '';

// Workaround for issue in https://github.com/Microsoft/vscode/issues/9448#issuecomment-244804026
if (process.platform === 'win32') {
currentFileDirPath = currentFileDirPath.substr(0, 1).toUpperCase() + currentFileDirPath.substr(1);
}

// In case of multiple workspaces, find current workspace by checking if current file is
// Find current workspace by checking if current file is
// under any of the workspaces in $GOPATH
for (let i = 1; i < workspaces.length; i++) {
for (let i = 0; i < workspaces.length; i++) {
let possibleCurrentWorkspace = path.join(workspaces[i], 'src');
if (currentFileDirPath.startsWith(possibleCurrentWorkspace)) {
// In case of nested workspaces, (example: both /Users/me and /Users/me/src/a/b/c are in $GOPATH)
Expand Down

3 comments on commit d417fd6

@maxtar
Copy link

@maxtar maxtar commented on d417fd6 Mar 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this commit Studio Code underscoring package main with error
"can't load package: package d:/GoProjects/src/max/hello: cannot find package "d:/GoProjects/src/max/hello" in any of:
C:\Go\src\d:\GoProjects\src\max\hello (from $GOROOT)
d:\GoProjects\src\d:\GoProjects\src\max\hello (from $GOPATH)"

@ramya-rao-a
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxtar

Workaround:

  • Uninstall Go extension
  • Download the vsix file Go-0.6.58.vsix
  • Run code --install-extension Go-0.5.58.vsix from the location where you downloaded the file

I am trying to understand all different scenarios where this occurs (and there are quite a few) and will publish the fix soon

@maxtar
Copy link

@maxtar maxtar commented on d417fd6 Apr 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanx for workaround!

Please sign in to comment.