Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting `GOPATH` for each vscode project

Setting the GOPATH variable global as an enviroment variable works fine with Visual Studio Code.

But setting a project specific variable globally doesn't seem very nice to me. Consider you have multiple Go projects, you would have to change this variable each time you, compile, debug, ... etc. a project.

Is there a possibility to set the GOPATH variable as a project variable in Visual Studio Code? Ether in settings.json or launch.json?

like image 243
Matthias Avatar asked Nov 21 '16 07:11

Matthias


2 Answers

set workspace settings, in windows:

  1. goto settings: ctrl+,
  2. set workspace setting:

    { 
         "go.gopath": "d:\\gopath;E:\\src"
    }
    

use ; for multiple path

  1. restart visual studio code to take effect.
like image 164
hustljian Avatar answered Sep 20 '22 21:09

hustljian


If your VSCode project directory is organized,

  1. go to Settings
  2. either search "Infer Gopath" or find this entry under Extensions/Go
  3. check the box

Then VSCode infers GOPATH from your workspace root, which solves my problem immediately. I believe this is explained in other answers. I am posting this just to give a shorter version.

like image 43
Louis Avatar answered Sep 19 '22 21:09

Louis