简体   繁体   English

用于 golang 的 VSCODE

[英]VSCODE for golang

I have been using VSCode forGolang and sometimes GoLand trial version.我一直在为 Golang 使用 VSCode,有时使用 GoLand 试用版。 I want to stick with VSCode but I cannot find the below things in the plugin.我想坚持使用 VSCode,但我在插件中找不到以下内容。 Can anyone tell me if it is possible or not谁能告诉我这是否可能

  • There is no way for me to have a pop-up show up to see the list of all functions, structs, interfaces in the file that I have open?没有办法让我弹出一个窗口来查看我打开的文件中所有函数、结构、接口的列表吗?
  • Is there a way to click on an interface and see who all implement it?有没有办法点一个接口,看看都有谁实现的?
  • Is there a way to click on a struct and see what all interfaces it implements?有没有办法单击一个结构并查看它实现的所有接口?

GoLand has all the 3 and that is what makes it amazing. GoLand 拥有所有这 3 个,这就是它的惊人之处。 Other than that most things are similar.除此之外,大多数事情都是相似的。

Actually it is possible to do all three things in VS Code as well. 实际上,在VS Code中也可以做全部三件事。

1. List of all functions, structs, interface - Code Outline 1.所有功能,结构,接口的列表-代码大纲

There is a great extension Code Outline that works very well with Go code. 有一个很棒的扩展代码大纲 ,可以很好地与Go代码一起使用。 I'm using it successfully without any problems. 我已成功使用它,没有任何问题。

代码大纲

2. Is there a way to click on an interface and see who all implement it? 2.是否可以单击某个界面,看看谁都实现了?

According to VS Code documentation , it is possible to go to definition using Ctrl + F12 shortcut. 根据VS Code 文档 ,可以使用Ctrl + F12快捷键进入定义。 It seems to work well for Go source code at this point. 此时,对于Go源代码来说似乎运行良好。

实施接口

3. Is there a way to click on a struct and see what all interfaces it implements? 3.是否可以单击结构并查看其实现的所有接口?

Similarly as with answer above, and according to documentation, Ctrl + F12 shortcut seems to be working well in that case. 与上述答案类似,并且根据文档,在这种情况下, Ctrl + F12快捷键似乎运行良好。

For an interface, this shows all the implementors of that interface and for abstract methods, this shows all concrete implementations of that method. 对于一个接口,它显示了该接口的所有实现者,对于抽象方法,这显示了该方法的所有具体实现。

实现接口

Just right click on interface/struct definition and select " Go to implementations ", it will pop up an context window.只需右键单击接口/结构定义和 select“ Go 到实现”,它会弹出一个上下文 window。

Internally it relies on guru which had been deprecated by golang team.在内部它依赖于被 golang 团队弃用的guru Guru does not support module as well. Guru 也不支持模块。

Newer plugin gopls relies on " Language Server Protocol(LSP) " which is actively developing by golang team, but I am not sure it has same functionality as "Go to implementations".较新的插件gopls依赖于 golang 团队正在积极开发的“ Language Server Protocol(LSP) ”,但我不确定它是否具有与“Go to implementations”相同的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM