diff --git a/src/goPath.ts b/src/goPath.ts index 34d12fa5c..e2f024992 100644 --- a/src/goPath.ts +++ b/src/goPath.ts @@ -34,7 +34,7 @@ export function getBinPathFromEnvVar(toolName: string, envVarValue: string, appe export function getBinPathWithPreferredGopath(toolName: string, preferredGopaths: string[], alternateTools?: { [key: string]: string; }) { if (binPathCache[toolName]) return binPathCache[toolName]; - const alternateTool = (alternateTools && alternateTools[toolName]) ? util.resolvePath(alternateTools[toolName]) : null; + const alternateTool = (alternateTools && alternateTools[toolName]) || null; if (alternateTool && path.isAbsolute(alternateTool) && fileExists(alternateTool)) { binPathCache[toolName] = alternateTool; return alternateTool; diff --git a/src/util.ts b/src/util.ts index 7903df0d0..e557a1d4e 100644 --- a/src/util.ts +++ b/src/util.ts @@ -371,7 +371,13 @@ function resolveToolsGopath(): string { } export function getBinPath(tool: string): string { - return getBinPathWithPreferredGopath(tool, (tool === 'go') ? [] : [getToolsGopath(), getCurrentGoPath()], vscode.workspace.getConfiguration('go', null).get('alternateTools')); + const alternateTools: { [key: string]: string; } = vscode.workspace.getConfiguration('go', null).get('alternateTools'); + + return getBinPathWithPreferredGopath( + tool, + (tool === 'go') ? [] : [getToolsGopath(), getCurrentGoPath()], + resolveObjectPaths(alternateTools), + ); } export function getFileArchive(document: vscode.TextDocument): string { @@ -501,6 +507,21 @@ export function timeout(millis: number): Promise { }); } + +/** + * Given an object with path attributes, resolve the paths of all attributes and return the new object. + */ +export function resolveObjectPaths(obj: { + [key: string]: string; +}): { + [key: string]: string; +} { + return Object.keys(obj).reduce( + (acc, key, idx) => ({ ...acc, [key]: resolvePath(obj[key]) }), + {} + ); +} + /** * Expands ~ to homedir in non-Windows platform and resolves ${workspaceFolder} or ${workspaceRoot} */