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

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
John Stableford committed Jun 4, 2019
1 parent f3ac072 commit 3927e9d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/goPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 22 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -501,6 +507,21 @@ export function timeout(millis: number): Promise<void> {
});
}


/**
* 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}
*/
Expand Down

0 comments on commit 3927e9d

Please # to comment.