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

Working with multiple GOPATHs #220

Closed
luebken opened this issue Mar 3, 2016 · 6 comments
Closed

Working with multiple GOPATHs #220

luebken opened this issue Mar 3, 2016 · 6 comments

Comments

@luebken
Copy link

luebken commented Mar 3, 2016

My current setup: I have a default GOPATH and I'm usually setting a new GOPATH to the current project I'm working on. Like export GOPATH=$(PWD).

From what I've read the Readme this setup should be supported:

In a terminal window with the GOPATH environment variable set to the GOPATH you want to work on, launch code.
https://github.com/Microsoft/vscode-go#using

But the GOPATH doesn't seemed to be used:

# In my CLI
$ export GOPATH=$(PWD)
$ env |grep GO
GOROOT=/usr/local/opt/go/libexec
GOPATH=/Users/mdl/workspace/myproject
code .
# In code 
# > "Go:Current GOPATH" => /Users/mdl/workspace/golang

Note: I've installed the Analysis Tools in the default GOPATH (/Users/mdl/workspace/golang) and I'm not asked to reinstall them when opening with a new GOPATH.

Should the work? How can I debug this problem?

@lukehoban
Copy link
Contributor

There was an issue with VS Code at one point where if you had any existing VS Code windows open before launching code . the env vars for the newly launched windows would get populated from the previous window, not the new shell. Could you try closing all of the VS Code windows and see if this works then?

Also - do you have a ~/.profile or similar which would be setting GOPATH to your /Users/mdl/workspace/golang folder?

@luebken
Copy link
Author

luebken commented Mar 4, 2016

Could you try closing all of the VS Code windows and see if this works then?

I always closed all windows.

Also - do you have a ~/.profile or similar which would be setting GOPATH to your
/Users/mdl/workspace/golang folder?

Yes. I did. in ~/.bash_profile and removing it did help. \o/

Do you have an idea why? As you see above env showed the current project path.

Also this means that in my setup I would need to re-install all the analysis tool for each project. Correct?

@saml
Copy link
Contributor

saml commented Mar 29, 2016

Looks like this extension overwrites:

process.env.GOPATH

Other environment variables persist.
For example,

shell> GOPATH="/foo/bar" FOOBAR="/foo/bar" code .

After VSCode is launched, go to Help > Toggle Developer Tools and check the following in Console:

> process.env.GOPATH
"/home/saml/go"  // eh?
> process.env.FOOBAR
"/foo/bar" // this is expected

Expected behavior is:

  1. If go.gopath is defined, this trumps GOPATH envvar.
  2. If go.gopath is not defined, use current session's GOPATH.

Isn't above expected behavior sane?

@lukehoban
Copy link
Contributor

@saml That expected behaviour should be what is implemented. In your example, I expect the results you are seeing come from having "go.gopath": "/home/saml/go" in your workspace or user settings in Code. Is that not the case?

If it's not, could you (a) make sure you close all Code windows and see if you get the same results? and (b) do you have a ~/.bash_profile or similar which is configuring the GOPATH? That shouldn't cause a problem, but curious if it's the case in your setup.

@saml
Copy link
Contributor

saml commented Mar 29, 2016

@lukehoban I'm using zsh, ubuntu.

# No workspace settings
➜ cat .vscode/settings.json
cat: .vscode/settings.json: No such file or directory

# User settings, but no go.gopath
➜ cat ~/.config/Code/User/settings.json 
// Place your settings in this file to overwrite the default settings
{
    "editor.fontSize": 18,
    "rust.rustfmtPath": "/home/sam/.multirust/toolchains/stable/cargo/bin/rustfmt",
    "go.buildOnSave": true,
    "go.lintOnSave": true,
    "go.vetOnSave": true,
    "go.buildFlags": [],
    "go.lintFlags": [],
    "go.vetFlags": [],
    "go.formatOnSave": true,
    "go.formatTool": "gofmt"
}

# Defining GOPATH in .zlogin
➜ grep GOPATH ~/.zshrc                
➜ grep GOPATH ~/.zshenv
➜ grep GOPATH ~/.zlogin
GOPATH="$HOME/code"

It's weird. Even if I use the following goMain.js:

'use strict';
function activate(ctx) {
}
exports.activate = activate;

And launch vscode as:

# vscode is symlink to /opt/VSCode/code
➜ GOPATH=/tmp/1 GOPATH_=/tmp/2 GoPath=/tmp/3 FOOBAR=/tmp/4 vscode .

I get the following:

process.env.GOPATH
"/home/sam/code"
process.env.GOPATH_
"/tmp/2"
process.env.GoPath
"/tmp/3"

It looks like it's related to the way vscode is executing. Variables defined in ~/.zshrc, ~/.zshenv, or ~/.zlogin cannot be overwritten in command line like:

# This is zsh
➜ grep FOOBAR ~/.zlogin
FOOBAR=1  # I define this variable in ~/.zloginecho $FOOBAR
1

➜ bash

# Now bash

$ echo $FOOBAR

$ FOOBAR=foobar   notdefinedinzshenv=wow vscode .

process.env.FOOBAR
"1"

process.env.notdefinedinzshenv
"wow"

Maybe vscode executes zsh (my default shell) as login shell overriding variables passed on commandline...

EDIT: VSCode does seem to execute shell as login shell. Tested this with bash as well.

chsh -s /bin/bash
vim ~/.bash_login  # export FOOBAR=1
# logout and login
FOOBAR=2 vscode .

process.env.FOOBAR
"1"

Out of curiosity, tested this with Atom editor as well:

FOOBAR=2 atom 

process.env.FOOBAR
"2"

atom respects FOOBAR=2 passed in command line.

@lukehoban
Copy link
Contributor

Thanks @saml for the investigation, and for opening microsoft/vscode#4779.

Based on that, it sounds like the root issue is in VS Code, and is now being tracked there. So I'm going to close this issue. Let us know if there's something seperate you see that we could do in vscode-go to help here.

@vscodebot vscodebot bot locked and limited conversation to collaborators Jan 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants