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

go.inferGopath should not ignore global gopath #1525

Closed
zero-master opened this issue Feb 19, 2018 · 9 comments
Closed

go.inferGopath should not ignore global gopath #1525

zero-master opened this issue Feb 19, 2018 · 9 comments
Milestone

Comments

@zero-master
Copy link

I've read: https://github.com/Microsoft/vscode-go/wiki/GOPATH-in-the-VS-Code-Go-extension

Set path X in environment variable $GOPATH and set go.inferGopath to true which infers the path to be Y.

Now If I go to the integrated terminal and go get any package, it will be installed in path X.

But that's not where vscode is looking for it.

So, can we make it more useful by appending the inferred $GOPATH to the one from the environment variable or alternating the $GOPATH so that the packages installed with go get from the integrated terminal are installed in the place where vscode will be looking for it?

See this: https://stackoverflow.com/a/46047870

@amkoehler
Copy link

Ran into this same exact issue. For now I'm ok with using a single go path instead of multiple, but it would be nice to reap the benefits of go.inferGopath. I think it's a great feature.

@merry-mongoose
Copy link

Yes, I also hope you can make the go.inferGopath better.
For now, if we set the go.inferGopath to true, the workspace root will be used as go path, and override the GOPATH variable. For me, I hope use both of them, but cannot now.

For GOPATH, it is a global go path for all workspace;
For workspaceRoot, it same as a local go path which only be used for current workspace.

If we can use both of them in a workspace when set go.inferGopath to true, looks like use "$GOPATH:${workspaceRoot}" (but we cannot set this value to go.gopath, it is not absolute path), it will be more flexible.
Thank you.

@cerlestes
Copy link

cerlestes commented Mar 1, 2018

👍

go.inferGopath should really set the GOPATH env variable to the appropriate value for the integrated terminal. The setting is currently completely useless to me, as I need to manually set the environment variable under terminal.integrated.env.windows for all of my go projects.

@ramya-rao-a
Copy link
Contributor

The request for terminal to use the same GOPATH as rest of the features of the Go extension is being tracked in #1578.

@merry-mongoose Can you explain a bit more on why having the setting "go.gopath": "the-global-gopath:${workspaceRoot}" doesnt work for you?

@merry-mongoose
Copy link

@ramya-rao-a
In my case, my project has not be created under local gopath. Such as, if my local go path is '/a/b/c', but my project is under /a/d/e.
It means, I need add 2 path into GOPATH environment variable. It will be looks like
'export $GOPATH=/a/b/c:/a/d/e'

If I do this in system environment, it works well. But the project path should not be added into system environment. It will make the GOPATH variable too long if there are many projects. And also, it will make the trouble to team members. So, I need add it into project settings in vs code.

There is a problem. the 'go.gopath' setting only allow the absolute path and '$workspaceRoot'. But I should not assign the absolute path which can work well on my machine to 'go.gopath' setting. it will make it cannot work on team members system after they pulled project from SCM.

So, I hope I can do 1 of following 2 choices.

  1. make the 'go.inferGopath' works separately. thus, when I have not set 'go.gopath', and 'go.inferGopath' is set to 'true', both of the global GOPATH and current workspace will be used as gopath.
  2. make the 'go.gopath' can apply environment variables. then I can do 'go.gopath="$GOPATH:${workspaceRoot}"' to make both of them be used.

Thank you

@galileo-pkm
Copy link

It seems that people are trying to solve some common issues by using the wrong tools without real understanding how their environment should be setup.
I will explain my usual setup here for reference and also why I think that the result of "'go.inferGopath" should be exposed in the shell.
The system (shell) $GOPATH should be initialized, in my case ~/go. The go shell tools can work without it, but if $GOPATH is not explicitly set, delve debuger will not work properly in vscode. In vscode, gotoolspath should point to $GOPATH, infer path should be enabled.
When setup like this vscode can find libraries installed in the system $GOPATH but also in the local project subdirectories. Also when installing libraries via vscode (not go get from terminal) those will be installed in the project folder and will not clutter the "system" go folder.

Only thing, that is left to do: while in vscode terminal set $GPATH to point to both locations, something like: export GOPATH=$GOPATH:$(go_infer_path). I usually right click on the project folder and do open in terminal and execute: export GOPATH=$GOPATH:$(pwd).

In short: there should be a setting in vscode that can enable something like this:

{
  "terminal.integrated.env.linux": {
    "GOPATH": ${env:GOPATH}:${infered_go_path}
  }
}

@ramya-rao-a
Copy link
Contributor

There are 2 separate problems here:

  • When using go.inferGopath, the global gopath gets ignored by the plugin which I want to address in this issue
  • The integrated terminal doesn't have any knowledge of the gopath determined by the plugin which is addressed in Use current gopath in integrated terminals #1578

For the first one, I agree we should add the global gopath to the inferred gopath. The one thing I am not sold on is whether we should prepend the global gopath to the inferred gopath or append it.

I lean on appending it, to keep the experience for folks who have been working with the inferred gopath consistent.

Note: If go.inferGopath is disabled and go.gopath is set, then the global gopath will not be added to anything.

Thoughts?

@galileo-pkm
Copy link

Agreed, appending the global gopath would keep the experience consistent and would resolve the initial issue, without breaking any customized setups (or at least I can't think of a way that would).

Even if it breaks something, one can always unset the global gopath as the default value for go tools is ~/go.

@ramya-rao-a ramya-rao-a changed the title Make go.inferGopath more useful go.inferGopath should not ignore global gopath Jun 3, 2018
@ramya-rao-a
Copy link
Contributor

This feature (including global gopath when go.inferGopath is enabled) is now out in the latest update to the Go extension (0.6.81)

@ramya-rao-a ramya-rao-a added this to the 0.6.81 milestone Jun 4, 2018
@vscodebot vscodebot bot locked and limited conversation to collaborators Jul 18, 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

6 participants