From f6936fa7c96b262d660c3efaffa17d102270ec71 Mon Sep 17 00:00:00 2001 From: Ramya Achutha Rao Date: Mon, 2 Oct 2017 13:30:13 -0700 Subject: [PATCH] Set GOPATH in env before running go list or get --- src/goBrowsePackage.ts | 8 +++++--- src/goGetPackage.ts | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/goBrowsePackage.ts b/src/goBrowsePackage.ts index 380ad0478..3968ffec6 100644 --- a/src/goBrowsePackage.ts +++ b/src/goBrowsePackage.ts @@ -10,7 +10,7 @@ import cp = require('child_process'); import { getGoRuntimePath } from './goPath'; import path = require('path'); import { getAllPackages } from './goPackages'; -import { getImportPath } from './util'; +import { getImportPath, getCurrentGoPath } from './util'; export function browsePackages() { let selectedText = ''; @@ -30,7 +30,7 @@ export function browsePackages() { showPackageFiles(selectedText, true); } -function showPackageFiles(pkg: string, showAllPkgsIfPkgNotFound: boolean) { +function showPackageFiles(pkg: string, showAllPkgsIfPkgNotFound: boolean) { const goRuntimePath = getGoRuntimePath(); if (!goRuntimePath) { return vscode.window.showErrorMessage('Could not locate Go path. Make sure you have Go installed'); @@ -40,7 +40,9 @@ function showPackageFiles(pkg: string, showAllPkgsIfPkgNotFound: boolean) { return showPackageList(); } - cp.execFile(goRuntimePath, ['list', '-f', '{{.Dir}}:{{.GoFiles}}:{{.TestGoFiles}}:{{.XTestGoFiles}}', pkg], (err, stdout, stderr) => { + const env = Object.assign({}, process.env, { GOPATH: getCurrentGoPath() }); + + cp.execFile(goRuntimePath, ['list', '-f', '{{.Dir}}:{{.GoFiles}}:{{.TestGoFiles}}:{{.XTestGoFiles}}', pkg], { env }, (err, stdout, stderr) => { if (!stdout || stdout.indexOf(':') === -1) { if (showAllPkgsIfPkgNotFound) { return showPackageList(); diff --git a/src/goGetPackage.ts b/src/goGetPackage.ts index 507752ecf..2becc8cf8 100644 --- a/src/goGetPackage.ts +++ b/src/goGetPackage.ts @@ -3,7 +3,7 @@ import vscode = require('vscode'); import cp = require('child_process'); import { getGoRuntimePath } from './goPath'; -import { getImportPath } from './util'; +import { getImportPath, getCurrentGoPath } from './util'; import { outputChannel } from './goStatus'; export function goGetPackage() { @@ -22,7 +22,9 @@ export function goGetPackage() { return vscode.window.showErrorMessage('Could not locate Go binaries. Make sure you have Go installed'); } - cp.execFile(goRuntimePath, ['get', '-v', importPath], (err, stdout, stderr) => { + const env = Object.assign({}, process.env, { GOPATH: getCurrentGoPath() }); + + cp.execFile(goRuntimePath, ['get', '-v', importPath], { env }, (err, stdout, stderr) => { // go get -v uses stderr to write output regardless of success or failure if (stderr !== '') { outputChannel.show();