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

Commit

Permalink
Common case of GOPATH being opened directly #1213
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Dec 30, 2017
1 parent 89a22cb commit 5f5cad5
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,31 @@ export function getCurrentGoPath(workspaceUri?: vscode.Uri): string {
}
const config = vscode.workspace.getConfiguration('go', workspaceUri);
let currentRoot = workspaceUri ? workspaceUri.fsPath : vscode.workspace.rootPath;

// Workaround for issue in https://github.com/Microsoft/vscode/issues/9448#issuecomment-244804026
if (process.platform === 'win32') {
currentRoot = currentRoot ? currentRoot.substr(0, 1).toUpperCase() + currentRoot.substr(1) : '';
currentFilePath = currentFilePath ? currentFilePath.substr(0, 1).toUpperCase() + currentFilePath.substr(1) : '';
}
const configGopath = config['gopath'] ? resolvePath(config['gopath'], currentRoot) : '';
const inferredGopath = config['inferGopath'] === true ? (getInferredGopath(currentRoot) || getInferredGopath(currentFilePath)) : '';

// Infer the GOPATH from the current root or the path of the file opened in current editor
// Last resort: Check for the common case where GOPATH itself is opened directly in VS Code
let inferredGopath: string;
if (config['inferGopath'] === true) {
inferredGopath = getInferredGopath(currentRoot) || getInferredGopath(currentFilePath);
if (!inferredGopath) {
try {
if (fs.statSync(path.join(currentRoot, 'src')).isDirectory()) {
inferredGopath = currentRoot;
}
}
catch (e) {
// No op
}
}
}

const configGopath = config['gopath'] ? resolvePath(config['gopath'], currentRoot) : '';
return inferredGopath ? inferredGopath : (configGopath || process.env['GOPATH']);
}

Expand Down

0 comments on commit 5f5cad5

Please sign in to comment.