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

fixed 1743, go.gopath and go.toolsGopath now expand ${env:XXX} #1991

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
10 changes: 8 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export function getToolsGopath(useCache: boolean = true): string {

function resolveToolsGopath(): string {
ramya-rao-a marked this conversation as resolved.
Show resolved Hide resolved

let toolsGopathForWorkspace = vscode.workspace.getConfiguration('go')['toolsGopath'] || '';
let toolsGopathForWorkspace = substituteEnv(vscode.workspace.getConfiguration('go')['toolsGopath'] || '');

// In case of single root, use resolvePath to resolve ~ and ${workspaceRoot}
if (!vscode.workspace.workspaceFolders || vscode.workspace.workspaceFolders.length <= 1) {
Expand All @@ -373,6 +373,12 @@ function resolveToolsGopath(): string {
}
}

export function substituteEnv(input: string): string {
return input.replace(/\${env:([^}]+)}/g, function (match, capture) {
return process.env[capture.trim()] || '';
});
}

export function getBinPath(tool: string): string {
return getBinPathWithPreferredGopath(tool, tool === 'go' ? [] : [getToolsGopath(), getCurrentGoPath()], vscode.workspace.getConfiguration('go', null).get('alternateTools'));
}
Expand Down Expand Up @@ -443,7 +449,7 @@ export function getCurrentGoPath(workspaceUri?: vscode.Uri): string {
}
}

const configGopath = config['gopath'] ? resolvePath(config['gopath'], currentRoot) : '';
const configGopath = config["gopath"] ? resolvePath(substituteEnv(config["gopath"]), currentRoot) : ""
Copy link
Contributor

Choose a reason for hiding this comment

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

The introduction of double quotes and the missing semicolon in this line is causing linting errors.

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

Expand Down