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

Fixes #623 Expand ~ to os.homedir() in gopath #768

Merged
merged 5 commits into from
Feb 6, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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/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 } 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,7 +187,7 @@ class Delve {
connectClient(port, host);
return;
}
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 (process.platform === 'win32' || !inputPath.startsWith('~')) ? inputPath : path.join(os.homedir(), inputPath.substr(1));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not resolve ~ on windows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because ~ being the home dir is a POSIX thing. Doesn't apply to Windows.

But I see your point, if there was a workspace setting for go path using ~ checked in to source control, then the same workspace should work on Windows machine.

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Windows has it too now - ~ is expanded (only in powershell), and os.homedir() returns the right thing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
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