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

Fixed wrong workspace when one gopath is the substring of another. #658

Merged
merged 2 commits into from
Nov 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,22 @@ export function canonicalizeGOPATHPrefix(filename: string): string {
if (!gopath) return filename;
let workspaces = gopath.split(path.delimiter);
let filenameLowercase = filename.toLowerCase();

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment here about the logic being used, so that the next person knows whats going on?
The unit tests are failing in travis due to linting issues. Run npm run lint locally and fix the reported errors.

// In case of multiple workspaces, find current workspace by checking if current file is
// under any of the workspaces in $GOPATH
let currentWorkspace: string = null;
for (let workspace of workspaces) {
if (filenameLowercase.substring(0, workspace.length) === workspace.toLowerCase()) {
return workspace + filename.slice(workspace.length);
// In case of nested workspaces, (example: both /Users/me and /Users/me/a/b/c are in $GOPATH)
// both parent & child workspace in the nested workspaces pair can make it inside the above if block
// Therefore, the below check will take longer (more specific to current file) of the two
if (filenameLowercase.substring(0, workspace.length) === workspace.toLowerCase()
&& (!currentWorkspace || workspace.length > currentWorkspace.length)) {
currentWorkspace = workspace;
}
}
return filename;

if (!currentWorkspace) return filename;
return currentWorkspace + filename.slice(currentWorkspace.length);
}

/**
Expand Down