没有”go to definition”和没有函数定义弹出窗口的问题是针对Golang代码的。

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

no "go to definition" and no function definition pop-up for golang code

问题

我正在使用Visual Studio Code来编写Golang代码。

对于这个特定的代码示例:https://golang.org/pkg/net/rpc/,我无法看到任何函数定义的弹出窗口,也无法使用在VSCode中按F12键的"转到定义"功能。但是我可以在计算机上的其他项目中看到定义的弹出窗口。

我已经在Ubuntu 16.04的.bashrc文件中使用env.sh设置了我的gopath。

所有的插件和Visual Studio Code版本都是最新的。我应该怎么做才能使用函数定义提示?

更新:问题现在已经通过设置以下内容解决:

export GOPATH=`pwd` 

而不是:

export GOPATH=${GOPATH}:`pwd`

谢谢大家!尽管我仍然不知道如何使用多个gopath。

英文:

I am using visual studio code to code in golang.

For this particular code example: https://golang.org/pkg/net/rpc/, I can't see any function definition pop-up, nor can I use "go to definition" in vscode by pressing F12. I can see the definition pop-up in other projects on my computer.

I have set my gopath in .bashrc in ubuntu 16.04 using the env.sh

All the plugin and visual studio code versions are the latest. What should I do to use the function definition prompt?

update: the problem is now solved by setting:

export GOPATH=`pwd` 

instead of:

export GOPATH=${GOPATH}:`pwd`

Thank you all!Though I still have no idea to have multiple gopath working.

答案1

得分: 13

这个问题出现在新版本或更新的vs code中。我的版本是1.22,当我尝试编辑Go扩展的设置以使用Go doc工具时,它开始在我的vs code中工作。

文件 > 首选项 > 设置 > 扩展 > Go(配置)

将文档工具从godoc设置为gogetdoc。如果你还没有下载gogetdoc,请先下载并重新启动vscode以加载该工具。

go get -u github.com/zmb3/gogetdoc

现在按下F12键可以跳转到定义处。希望对你有帮助。

英文:

This issue is in new versions or updates of vs code. My version is 1.22, It started working in my vs code when I tried to edit the settings of go extension for Go doc tool in

File > Preferences > Settings > Extensions > Go(Configuration)

Set Docs Tool from godoc to gogetdoc. If you have not downloaded gogetdoc. Download it first and restart vscode for it to load the tool.

go get -u github.com/zmb3/gogetdoc

Now Press F12 to go to definition. I hope it helps.

答案2

得分: 0

你需要关闭go:use语言服务器,当你使用语言服务器时,go:docs工具将不适用。

语言服务器对大多数代码功能都能正常工作,但是你无法跳转到第三方包中某些函数的定义。

英文:

You need to close go:use the language server, go:docs tools will not be applicable when you use language server.

Language server works fine for most of the code stuffs, but you cannot go to definition of some functions in third-party packages.

答案3

得分: 0

如果有助于其他人,我还要添加一个我遇到并解决的导致相同问题的问题:

  • 问题:无法跳转到定义
  • go.mod 文件被 VsCode 标记为红色,表示某个模块未成功安装
  • 我找到了该模块(X)并手动安装了它,使用命令 go get X
  • 重新启动了 VsCode

这样解决了跳转到定义功能的问题。

英文:

In case it helps someone else I am also adding an issue I faced and resolved that caused the same problem:

  • Issue: go to definition not working
  • go.mod file was red(highlighted by VsCode) which meant that a module was not installed successfully
  • I found the module (X) and installed it manually go get X
  • Restarted VsCode

This resolved the issue with the go to definition functionality

答案4

得分: 0

在我的情况下,只需运行go mod tidy

英文:

In my case, just run go mod tidy.

答案5

得分: 0

我遇到了这个问题,原因是供应商不一致。所以,我执行了以下命令,问题就解决了。

go mod vendor
go mod tidy
英文:

I faced this issue due to inconsistent vendoring. So, I executed the following commands and was good to go.

go mod vendor
go mod tidy

huangapple
  • 本文由 发表于 2017年1月29日 10:22:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/41917033.html
匿名

发表评论

匿名网友

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

确定