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

Use GOPATH from env if dlv not found #725

Merged
merged 1 commit into from
Jan 19, 2017
Merged
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
6 changes: 6 additions & 0 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ class Delve {
return;
}
let dlv = getBinPath('dlv');

// If dlv not found, try using the GOPATH that was set in env in launch.json
if (!existsSync(dlv) && env['GOPATH']) {
dlv = getBinPath('dlv', env['GOPATH']);
}

log('Using dlv at: ', dlv);
if (!existsSync(dlv)) {
return reject(`Cannot find Delve debugger at ${dlv}. Ensure it is in your "GOPATH/bin" or "PATH".`);
Expand Down
16 changes: 8 additions & 8 deletions src/goPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import os = require('os');
let binPathCache: { [bin: string]: string; } = {};
let runtimePathCache: string = '';

export function getBinPathFromEnvVar(toolName: string, envVar: string, appendBinToPath: boolean): string {
export function getBinPathFromEnvVar(toolName: string, envVarValue: string, appendBinToPath: boolean): string {
toolName = correctBinname(toolName);
if (process.env[envVar]) {
let paths = process.env[envVar].split(path.delimiter);
if (envVarValue) {
let paths = envVarValue.split(path.delimiter);
for (let i = 0; i < paths.length; i++) {
let binpath = path.join(paths[i], appendBinToPath ? 'bin' : '', toolName);
if (fileExists(binpath)) {
Expand All @@ -30,29 +30,29 @@ export function getBinPathFromEnvVar(toolName: string, envVar: string, appendBin
return null;
}

export function getBinPath(binname: string) {
export function getBinPath(binname: string, goPath: string = null) {
if (binPathCache[correctBinname(binname)]) return binPathCache[correctBinname(binname)];

// First search VSCODE_GOTOOLS' bin folder
let pathFromToolsGoPath = getBinPathFromEnvVar(binname, 'VSCODE_GOTOOLS', true);
let pathFromToolsGoPath = getBinPathFromEnvVar(binname, process.env['VSCODE_GOTOOLS'], true);
if (pathFromToolsGoPath) {
return pathFromToolsGoPath;
}

// Then search each GOPATH workspace's bin folder
let pathFromGoPath = getBinPathFromEnvVar(binname, 'GOPATH', true);
let pathFromGoPath = getBinPathFromEnvVar(binname, goPath ? goPath : process.env['GOPATH'], true);
if (pathFromGoPath) {
return pathFromGoPath;
}

// Then search PATH parts
let pathFromPath = getBinPathFromEnvVar(binname, 'PATH', false);
let pathFromPath = getBinPathFromEnvVar(binname, process.env['PATH'], false);
if (pathFromPath) {
return pathFromPath;
}

// Finally check GOROOT just in case
let pathFromGoRoot = getBinPathFromEnvVar(binname, 'GOROOT', true);
let pathFromGoRoot = getBinPathFromEnvVar(binname, process.env['GOROOT'], true);
if (pathFromGoRoot) {
return pathFromGoRoot;
}
Expand Down