Go 的 ctag 数据库
如何为 Go 源代码生成标签文件
在 mac 中,我安装了 exuberant ctags ,并在源目录中尝试了以下命令,
ctags -f gosource.tags -R `pwd`
但是,它不考虑 *.go 文件。我必须使用 -h 选项吗?但是,根据手册,它不是仅适用于头文件吗?
请给我正确的命令,以便我可以在 vim 中使用标签文件。我也更喜欢绝对路径,这样我就可以将文件保存在任何地方,
谢谢。
编辑: 我假设当前的 ctags 支持 Go,请参阅 http://groups.google.com /group/golang-nuts/browse_thread/thread/3a4848db231b02c9。
How to generate tags file for Go source
In mac, I installed exuberant ctags , and tried the below command in source directory
ctags -f gosource.tags -R `pwd`
But, it doesn't consider *.go files. Do I have to use -h option? But, isn't it only for header files, as per the manual?
Please give me the correct command so that I can use the tags file with vim. I also prefer absolute path so that I can keep the file anywhere
Thanks.
Edit:
I assumed current ctags support Go, seeing http://groups.google.com/group/golang-nuts/browse_thread/thread/3a4848db231b02c9.
but, http://ctags.sourceforge.net/languages.html desn't have go listed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我看到了你的帖子,摸索了一下试图找到一个适合这项工作的好工具,尝试了 ctags,但最终不满意。我在 Go 中编写了一个程序“gotags”,它为 Go 代码生成 ctags 文件。它比当前的 ctags 支持更好,因为例如,它标记结构字段名称以及结构名称本身。您可以在这里获取它:https://github.com/necro351/gotags。
它是一个不错的简短的 Go 程序,因为它使用标准库解析器,除了良好的 Go 解析和标记之外没有任何额外的功能。只需检查一下(或去获取它)并进行安装即可。另外,如果您有任何关于改进它的建议或想法,请告诉我。
编辑:我是一个活跃的 Gopher,因此随着时间的推移和使用它,我会更新这个工具。
编辑:我不再积极开发 Go。但我的工具非常很短,而且几乎可以按原样工作,所以它应该“正常工作”:)
I saw your post, bumbled around a bit trying to find a good tool for the job, tried ctags, and ultimately was unsatisfied. I wrote a program 'gotags' in Go that generates a ctags file for Go code. Its better than the current ctags support because, for example, it tags struct field names as well as the struct name itself. You can get it here: https://github.com/necro351/gotags.
Its a nice short simple Go program because it uses the standard library parser and has no extra features other than good Go parsing and tagging. Just check it out (or go get it) and do a go install. Also, if you have any suggestions or ideas about improving it, let me know.
Edit: I am an active Gopher and so will be updating this tool over time and as I use it.
Edit: I am not actively developing Go anymore. But my tool is very short and pretty much works as is so it should "just work" :)
universal-ctags 支持 Go。它是 exuberant-ctags 的后继者,并且工作得非常好。请参阅此处查看手册页。
universal-ctags supports Go. It's the successor of exuberant-ctags and works perfectly fine. See here for the man pages.
检查 Go Dashborad/Projects 的“标签生成器”部分。我不知道这些工具的状态。
编辑 2011-11-22:今天宣布最新的 egotags 分叉(可以循环引用;-)
Check Go Dashborad/Projects, section "Tag Generators". Status of those tools is not known to me.
Edit 2011-11-22: Latest egotags fork announced today (cyclic reference possible ;-)
将以下内容添加到 ~/.ctags
(来自 http:// /go-wise.blogspot.com/2011/09/using-ctags-with-go.html)
Add the following to ~/.ctags
(From http://go-wise.blogspot.com/2011/09/using-ctags-with-go.html)
确实适用于 ctags 5.8。与上一张海报相比,有一个细微的变化,ctags 需要在正则表达式行的末尾使用唯一的 1 字符类型。因此
/d,func/
应该直观地读取/f,func/
。这允许 ctags 区分和识别类型,允许 ctags --go-types=fvt ieDoes indeed work with ctags 5.8. One slight change from the previous poster, ctags requires unique 1-char types at the ends of the regex lines. Thus
/d,func/
should read/f,func/
intuitively. This allows the ctags to distinguish between and identify types, allowingctags --go-types=fvt
i.e.