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

Commit

Permalink
Fixes #623 Expand ~ to os.homedir() in gopath (#768)
Browse files Browse the repository at this point in the history
* Fixes #623 Expand ~ to os.homedir() in gopath

* Add null/empty string check

* Support ~in Windows as well

* Switch the condition
  • Loading branch information
ramya-rao-a authored Feb 6, 2017
1 parent 4a58c36 commit ab35627
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { readFileSync, existsSync, lstatSync } from 'fs';
import { basename, dirname } from 'path';
import { spawn, ChildProcess, execSync, spawnSync } from 'child_process';
import { Client, RPCConnection } from 'json-rpc2';
import { getBinPathWithPreferredGopath } from '../goPath';
import { getBinPathWithPreferredGopath, resolvePath } from '../goPath';
import * as logger from 'vscode-debug-logger';

require('console-stamp')(console);
Expand Down Expand Up @@ -187,9 +187,10 @@ class Delve {
connectClient(port, host);
return;
}

if (!env) env = {};

let dlv = getBinPathWithPreferredGopath('dlv', env['GOPATH']);
let dlv = getBinPathWithPreferredGopath('dlv', resolvePath(env['GOPATH']));

if (!existsSync(dlv)) {
verbose(`Couldnt find dlv at ${process.env['GOPATH']}${env['GOPATH'] ? ', ' + env['GOPATH'] : ''} or ${process.env['PATH']}`);
Expand Down
4 changes: 2 additions & 2 deletions src/goInstallTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import path = require('path');
import os = require('os');
import cp = require('child_process');
import { showGoStatus, hideGoStatus } from './goStatus';
import { getGoRuntimePath } from './goPath';
import { getGoRuntimePath, resolvePath } from './goPath';
import { outputChannel } from './goStatus';
import { getBinPath, getToolsGopath, getGoVersion, SemVersion, isVendorSupported } from './util';

Expand Down Expand Up @@ -207,7 +207,7 @@ export function updateGoPathGoRootFromConfig() {

let gopath = vscode.workspace.getConfiguration('go')['gopath'];
if (gopath) {
process.env['GOPATH'] = gopath.replace(/\${workspaceRoot}/g, vscode.workspace.rootPath);
process.env['GOPATH'] = resolvePath(gopath, vscode.workspace.rootPath);
}

let inferGoPath = vscode.workspace.getConfiguration('go')['inferGopath'];
Expand Down
11 changes: 11 additions & 0 deletions src/goPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,15 @@ function fileExists(filePath: string): boolean {

export function clearCacheForTools() {
binPathCache = {};
}

/**
* Exapnds ~ to homedir in non-Windows platform and replaces ${workspaceRoot} token with given workspaceroot
*/
export function resolvePath(inputPath: string, workspaceRoot?: string): string {
if (!inputPath || !inputPath.trim()) return inputPath;
if (workspaceRoot) {
inputPath = inputPath.replace(/\${workspaceRoot}/g, workspaceRoot);
}
return inputPath.startsWith('~') ? path.join(os.homedir(), inputPath.substr(1)) : inputPath;
}
4 changes: 2 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import vscode = require('vscode');
import path = require('path');
import { getGoRuntimePath, getBinPathWithPreferredGopath} from './goPath';
import { getGoRuntimePath, getBinPathWithPreferredGopath, resolvePath} from './goPath';
import cp = require('child_process');
import TelemetryReporter from 'vscode-extension-telemetry';

Expand Down Expand Up @@ -253,7 +253,7 @@ export function getToolsGopath(): string {
let goConfig = vscode.workspace.getConfiguration('go');
let toolsGopath = goConfig['toolsGopath'];
if (toolsGopath) {
toolsGopath = toolsGopath.replace(/\${workspaceRoot}/g, vscode.workspace.rootPath);
toolsGopath = resolvePath(toolsGopath, vscode.workspace.rootPath);
}
return toolsGopath;
}
Expand Down

0 comments on commit ab35627

Please sign in to comment.