dtc88867 2018-10-19 05:27
浏览 1460
已采纳

为vscode项目/终端设置$ GOPATH

I want to set $GOPATH for each vscode project/workspace. Right now, in .vscode/settings.json, I have:

{
    "go.gopath": "$HOME/codes/huru"
}

I close vscode and reopened, and at the command line terminal, I echo $GOPATH, and it's empty. I was hoping that vscode would read the env variable from "go.gopath", but it seems not have to done so.

Does anyone know how to do this?

enter image description here

enter image description here

  • 写回答

1条回答 默认 最新

  • doutuoji8418 2018-10-19 06:49
    关注

    Setting the go.gopath on user settings or workspace settings will replace the GOPATH value on the VS Code. This GOPATH value is the one that showing up when Go: Current GOPATH command is executed, not the $GOPATH environment variable.

    The go.gopath value will not replace the $GOPATH environment variable.

    Explanation from GOPATH in the VS Code Go extension:

    Out of the box, the extension uses the value of the environment variable GOPATH. From Go 1.8 onwards, if no such environment variable is set, then the default GOPATH as deciphered from the command go env is used.

    Setting go.gopath in User settings overrides the GOPATH that was derived from the above logic. Setting go.gopath in Workspace settings overrides the one from User settings. You can set multiple folders as GOPATH in this setting. Note that they should be ; separated in Windows and : separated otherwise.

    Below I add an image that might help you.

    • Basically I already have $GOPATH env variable ready on my local with certain value. Then I set the go.gopath on the user settings (with different value compared to the $GOPATH). When I execute command Go: Current GOPATH, a popup on the bottom right appear, showing the very same value like on my go.gopath settings. I put red line on all of this.
    • But, when I execute shell command echo $GOPATH on terminal, the output is still the $GOPATH value from my env variable (blue line). This is because go.gopath setting will not replace the $GOPATH env variable.

    enter image description here


    In your case, the echo $GOPATH return empty output because you haven't set the $GOPATH environment variable.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 数据排序,可选择排序方向
  • ¥15 修改一下代码,考虑进程到达时间不同的情况
  • ¥15 华为nova10pro ,关闭热动热点用量记录
  • ¥15 帮我看看这是个啥题,带解题过程和结果,条件如下FCF = 290471.33 g1 = 15% r = 8% g2 = 4% n = 5
  • ¥15 edem模拟颗粒不显示或者生成失败
  • ¥15 Python代码编写
  • ¥15 php 将rtmp协议转hls协议,无法播放
  • ¥20 python代码编写
  • ¥20 使用MPI广播数据遇到阻塞
  • ¥15 TinyMCE如何去掉自动弹出的“链接…”工具?