Skip to content

Commit

Permalink
Infer Gopath from current file if not able to infer from workspace go…
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Dec 29, 2017
1 parent 6b0fd86 commit 89a22cb
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,20 @@ export function getToolsEnvVars(): any {
}

export function getCurrentGoPath(workspaceUri?: vscode.Uri): string {
if (!workspaceUri && vscode.window.activeTextEditor && vscode.workspace.getWorkspaceFolder(vscode.window.activeTextEditor.document.uri)) {
workspaceUri = vscode.workspace.getWorkspaceFolder(vscode.window.activeTextEditor.document.uri).uri;
let currentFilePath: string;
if (vscode.window.activeTextEditor && vscode.workspace.getWorkspaceFolder(vscode.window.activeTextEditor.document.uri)) {
workspaceUri = workspaceUri || vscode.workspace.getWorkspaceFolder(vscode.window.activeTextEditor.document.uri).uri;
currentFilePath = vscode.window.activeTextEditor.document.uri.fsPath;
}
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);
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) : '';
const inferredGopath = config['inferGopath'] === true ? (getInferredGopath(currentRoot) || getInferredGopath(currentFilePath)) : '';

return inferredGopath ? inferredGopath : (configGopath || process.env['GOPATH']);
}
Expand Down

0 comments on commit 89a22cb

Please sign in to comment.