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
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/goLint.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path = require('path');
import vscode = require('vscode');
import { getToolsEnvVars, resolvePath, runTool, ICheckResult, handleDiagnosticErrors, getWorkspaceFolderPath } from './util';
import { getToolsEnvVars, resolvePath, runTool, ICheckResult, handleDiagnosticErrors, getWorkspaceFolderPath, getToolsGopath } from './util';
import { outputChannel } from './goStatus';
import { diagnosticsStatusBarItem } from './goStatus';
/**
Expand Down Expand Up @@ -87,7 +87,7 @@ export function goLint(fileUri: vscode.Uri, goConfig: vscode.WorkspaceConfigurat
if (goConfig['toolsGopath']) {
// gometalinter will expect its linters to be in the GOPATH
// So add the toolsGopath to GOPATH
lintEnv['GOPATH'] += path.delimiter + goConfig['toolsGopath'];
lintEnv['GOPATH'] += path.delimiter + getToolsGopath();
}
}
if (lintTool === 'golangci-lint') {
Expand Down
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) : '';
return inferredGopath ? inferredGopath : (configGopath || process.env['GOPATH']);
}

Expand Down