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

Commit

Permalink
Use settings for separate location for installing Go tools
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Jan 21, 2017
1 parent 4ead817 commit 3af5413
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 41 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,11 @@
"godoc",
"gogetdoc"
]
},
"go.toolsGopath": {
"type": "string",
"default": "",
"description": "Location to install the Go tools that the extension depends on if you don't want them in your GOPATH."
}
}
}
Expand Down
9 changes: 2 additions & 7 deletions src/debugAdapter/goDebug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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 { getBinPath } from '../goPath';
import { getBinPathWithPreferredGopath } from '../goPath';

require('console-stamp')(console);

Expand Down Expand Up @@ -168,12 +168,7 @@ class Delve {
connectClient(port, host);
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']);
}
let dlv = getBinPathWithPreferredGopath('dlv', env['GOPATH']);

log('Using dlv at: ', dlv);
if (!existsSync(dlv)) {
Expand Down
4 changes: 2 additions & 2 deletions src/goCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import cp = require('child_process');
import path = require('path');
import os = require('os');
import fs = require('fs');
import { getBinPath, getGoRuntimePath } from './goPath';
import { getGoRuntimePath } from './goPath';
import { getCoverage } from './goCover';
import { outputChannel } from './goStatus';
import { promptForMissingTool } from './goInstallTools';
import { parseFilePrelude } from './util';
import { getBinPath, parseFilePrelude } from './util';

export interface ICheckResult {
file: string;
Expand Down
3 changes: 2 additions & 1 deletion src/goCover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import cp = require('child_process');
import path = require('path');
import os = require('os');
import fs = require('fs');
import { getBinPath, getGoRuntimePath } from './goPath';
import { getGoRuntimePath } from './goPath';
import { getBinPath } from './util';
import rl = require('readline');
import { outputChannel } from './goStatus';

Expand Down
3 changes: 1 addition & 2 deletions src/goDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import vscode = require('vscode');
import cp = require('child_process');
import path = require('path');
import { getBinPath } from './goPath';
import { byteOffsetAt } from './util';
import { byteOffsetAt, getBinPath } from './util';
import { promptForMissingTool } from './goInstallTools';
import { getGoVersion, SemVersion, goKeywords, isPositionInString } from './util';

Expand Down
3 changes: 1 addition & 2 deletions src/goFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import vscode = require('vscode');
import cp = require('child_process');
import path = require('path');
import { isDiffToolAvailable, getEdits, getEditsFromUnifiedDiffStr } from '../src/diffUtils';
import { getBinPath } from './goPath';
import { promptForMissingTool } from './goInstallTools';
import { sendTelemetryEvent } from './util';
import { sendTelemetryEvent, getBinPath } from './util';

export class Formatter {
private formatCommand = 'goreturns';
Expand Down
2 changes: 1 addition & 1 deletion src/goGenerateTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import path = require('path');
import vscode = require('vscode');
import util = require('util');

import { getBinPath } from './goPath';
import { getBinPath } from './util';
import { promptForMissingTool } from './goInstallTools';
import { GoDocumentSymbolProvider } from './goOutline';

Expand Down
3 changes: 1 addition & 2 deletions src/goImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import vscode = require('vscode');
import cp = require('child_process');
import { getBinPath } from './goPath';
import { parseFilePrelude, isVendorSupported } from './util';
import { parseFilePrelude, isVendorSupported, getBinPath } from './util';
import { documentSymbols } from './goOutline';
import { promptForMissingTool } from './goInstallTools';
import path = require('path');
Expand Down
13 changes: 7 additions & 6 deletions src/goInstallTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import path = require('path');
import os = require('os');
import cp = require('child_process');
import { showGoStatus, hideGoStatus } from './goStatus';
import { getBinPath, getGoRuntimePath } from './goPath';
import { getGoRuntimePath } from './goPath';
import { outputChannel } from './goStatus';
import { getGoVersion, SemVersion, isVendorSupported } from './util';
import { getBinPath, getGoVersion, SemVersion, isVendorSupported } from './util';

let updatesDeclinedTools: string[] = [];

Expand Down Expand Up @@ -136,11 +136,12 @@ function installTools(goVersion: SemVersion, missing?: string[]) {
});
}

// If the VSCODE_GOTOOLS environment variable is set, use
// its value as the GOPATH for the "go get" child precess.
// If the go.toolsGopath is set, use
// its value as the GOPATH for the "go get" child process.
let goConfig = vscode.workspace.getConfiguration('go');
let envWithSeparateGoPathForTools = null;
if (process.env['VSCODE_GOTOOLS']) {
envWithSeparateGoPathForTools = Object.assign({}, envForTools, {GOPATH: process.env['VSCODE_GOTOOLS']});
if (goConfig['toolsGopath']) {
envWithSeparateGoPathForTools = Object.assign({}, envForTools, {GOPATH: goConfig['toolsGopath']});
}

missing.reduce((res: Promise<string[]>, tool: string) => {
Expand Down
2 changes: 1 addition & 1 deletion src/goOutline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import vscode = require('vscode');
import cp = require('child_process');
import path = require('path');
import { getBinPath } from './goPath';
import { getBinPath } from './util';
import { promptForMissingTool, promptForUpdatingTool } from './goInstallTools';

// Keep in sync with https://github.com/lukehoban/go-outline
Expand Down
14 changes: 7 additions & 7 deletions src/goPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ export function getBinPathFromEnvVar(toolName: string, envVarValue: string, appe
return null;
}

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

// First search VSCODE_GOTOOLS' bin folder
let pathFromToolsGoPath = getBinPathFromEnvVar(binname, process.env['VSCODE_GOTOOLS'], true);
if (pathFromToolsGoPath) {
return pathFromToolsGoPath;
// Search in the preferred GOPATH workspace's bin folder
let pathFrompreferredGoPath = getBinPathFromEnvVar(binname, preferredGopath, true);
if (pathFrompreferredGoPath) {
return pathFrompreferredGoPath;
}

// Then search each GOPATH workspace's bin folder
let pathFromGoPath = getBinPathFromEnvVar(binname, goPath ? goPath : process.env['GOPATH'], true);
// Then search user's GOPATH workspace's bin folder
let pathFromGoPath = getBinPathFromEnvVar(binname, process.env['GOPATH'], true);
if (pathFromGoPath) {
return pathFromGoPath;
}
Expand Down
3 changes: 1 addition & 2 deletions src/goReferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import vscode = require('vscode');
import cp = require('child_process');
import path = require('path');
import { getBinPath } from './goPath';
import { byteOffsetAt, canonicalizeGOPATHPrefix } from './util';
import { getBinPath, byteOffsetAt, canonicalizeGOPATHPrefix } from './util';
import { promptForMissingTool } from './goInstallTools';

export class GoReferenceProvider implements vscode.ReferenceProvider {
Expand Down
3 changes: 1 addition & 2 deletions src/goRename.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

import vscode = require('vscode');
import cp = require('child_process');
import { getBinPath } from './goPath';
import { byteOffsetAt, canonicalizeGOPATHPrefix } from './util';
import { getBinPath, byteOffsetAt, canonicalizeGOPATHPrefix } from './util';
import { getEditsFromUnifiedDiffStr, isDiffToolAvailable, FilePatch, Edit } from '../src/diffUtils';
import { promptForMissingTool } from './goInstallTools';

Expand Down
3 changes: 1 addition & 2 deletions src/goSuggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import vscode = require('vscode');
import cp = require('child_process');
import { dirname, basename } from 'path';
import { getBinPath } from './goPath';
import { parameters, parseFilePrelude, isPositionInString } from './util';
import { getBinPath, parameters, parseFilePrelude, isPositionInString } from './util';
import { promptForMissingTool } from './goInstallTools';
import { listPackages, getTextEditForAddImport } from './goImport';

Expand Down
2 changes: 1 addition & 1 deletion src/goSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import vscode = require('vscode');
import cp = require('child_process');
import { getBinPath } from './goPath';
import { getBinPath } from './util';
import { promptForMissingTool } from './goInstallTools';

// Keep in sync with github.com/newhook/go-symbols'
Expand Down
7 changes: 6 additions & 1 deletion 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 } from './goPath';
import { getGoRuntimePath, getBinPathWithPreferredGopath} from './goPath';
import cp = require('child_process');
import TelemetryReporter from 'vscode-extension-telemetry';

Expand Down Expand Up @@ -245,3 +245,8 @@ export function isPositionInString(document: vscode.TextDocument, position: vsco
doubleQuotesCnt += lineTillCurrentPosition.startsWith('\"') ? 1 : 0;
return doubleQuotesCnt % 2 === 1;
}

export function getBinPath(tool: string): string {
let goConfig = vscode.workspace.getConfiguration('go');
return getBinPathWithPreferredGopath(tool, goConfig['toolsGopath']);
}
3 changes: 1 addition & 2 deletions test/go.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ import cp = require('child_process');
import { getEditsFromUnifiedDiffStr, getEdits } from '../src/diffUtils';
import jsDiff = require('diff');
import { testCurrentFile } from '../src/goTest';
import { getGoVersion, isVendorSupported } from '../src/util';
import { getBinPath, getGoVersion, isVendorSupported } from '../src/util';
import { documentSymbols } from '../src/goOutline';
import { listPackages } from '../src/goImport';
import { generateTestCurrentFile, generateTestCurrentPackage, generateTestCurrentFunction } from '../src/goGenerateTests';
import { getBinPath } from '../src/goPath';

suite('Go Extension Tests', () => {
let gopath = process.env['GOPATH'];
Expand Down

0 comments on commit 3af5413

Please sign in to comment.