如何获取关于 Go 变量类型的信息

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

How can I get information about type of a Go variable

问题

假设我在Go中有以下代码:

foo, bar := someFunc(baz)

我想创建一个Vim函数,在编辑文件时检查foobar的类型。

有没有任何工具或可靠的Go包函数信息来源可以使用?至于文件中声明的函数,我考虑简单地解析该文件中声明的所有函数。

英文:

Suppose I have the following code in Go:

foo, bar := someFunc(baz) 

I would like to create a Vim function to check type of foo or bar when editing a file.

Is there any tool or reliable source of information for functions from Go's packages I could use or? As for the functions declared in the file I'm editing I was thinking about simply parsing all the functions declared in that file.

答案1

得分: 3

你正在寻找类似godef的东西。

> 如果给出了-t标志,还将打印表达式的类型。-a标志会导致打印表达式的所有公共成员(字段和方法)以及它们的位置;-A标志也会打印私有成员。

我知道它被各种vim和emacs脚本使用。

英文:

You are looking for something like godef

> If the -t flag is given, the type of the expression will also be
> printed. The -a flag causes all the public members (fields and
> methods) of the expression, and their location, to be printed also;
> the -A flag prints private members too.

I know it is being used by various vim and emacs scripts.

答案2

得分: 0

Go Oracle可以实现这个功能以及更多功能。

vim-go是一个完整的用于Go的vim设置。
它包括与前面提到的godef的集成(作为:GoDef)以及Go oracle的集成(作为:GoImplements、:GoCallees、:GoReferrers等),以及其他工具。

英文:

The Go Oracle does this and much more.

vim-go is a complete vim setup for Go.
It includes integration with the previously mentioned godef (as :GoDef) and Go oracle (as :GoImplements, :GoCallees, :GoReferrers, etc) as well as other tools.

huangapple
  • 本文由 发表于 2015年1月8日 03:32:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/27827199.html
匿名

发表评论

匿名网友

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

确定