在VSCode中,Golang的自动补全/智能感知功能无法正常工作。

huangapple go评论78阅读模式
英文:

autocomplete/intelliSense not working for golang in vscode

问题

我尝试了以下几件事情:

  1. 重新启动了VSCode。
  2. 从Google团队为VSCode安装了Go插件,并进行了卸载和重新安装。
  3. 在代码仓库中使用go get golang.org/x/tools/gopls@latest命令运行了gopls服务器。
英文:

I tried below things

  1. Restart of VSCode
  2. Uninstalled and installed Go plugin from google team for VSCode
  3. Ran gopls server in code repo using go get golang.org/x/tools/gopls@latest

答案1

得分: 0

终于,我成功解决了这个问题。我的项目需要设置export CGO_LDFLAGS_ALLOW=".*"环境变量。

所以,我在VSCode的Go插件的settings.json文件中添加了以下部分:

"go.toolsEnvVars": {        
    "CGO_LDFLAGS_ALLOW":".*"
}

之后,所有的模块都成功加载,并且VSCode能够提供智能感知功能。

英文:

Finally, I was able to solve this problem. My project was required export CGO_LDFLAGS_ALLOW=".*" env var to be set.

So, I added below section to the settings.json of the Go plugin for vscode

 "go.toolsEnvVars": {        
    "CGO_LDFLAGS_ALLOW":".*"
 }

After that, all the modules were loaded successfully and VSCode was able to provide intelliSense.

答案2

得分: -1

有时候 vscode 无法检测到 GOPATHGOROOT,可以尝试在用户设置(JSON)中手动设置它们,像这样:

  "go.gopath": "..路径..",
  "go.goroot": "..路径..",
英文:

Sometimes vscode do not detect the GOPATH and GOROOT, try to set them manualy in the user settings (JSON) like so :

  "go.gopath": "..path..",
  "go.goroot": "..path..",

huangapple
  • 本文由 发表于 2023年2月2日 23:11:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75325183.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定