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

Commit

Permalink
Set GOPATH in env before running go list or get
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Oct 2, 2017
1 parent e231f52 commit f6936fa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/goBrowsePackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand All @@ -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');
Expand All @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions src/goGetPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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();
Expand Down

0 comments on commit f6936fa

Please sign in to comment.