Go的ctag数据库

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

ctag database for Go

问题

如何为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。

但是,http://ctags.sourceforge.net/languages.html上没有列出go。

英文:

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.

答案1

得分: 48

将以下内容添加到~/.ctags文件中:

--langdef=Go
--langmap=Go:.go
--regex-Go=/func([ \t]+\([^)]+\))?[ \t]+([a-zA-Z0-9_]+)//d,func/
--regex-Go=/var[ \t]+([a-zA-Z_][a-zA-Z0-9_]+)//d,var/
--regex-Go=/type[ \t]+([a-zA-Z_][a-zA-Z0-9_]+)//d,type/

(来源:http://go-wise.blogspot.com/2011/09/using-ctags-with-go.html)

英文:

Add the following to ~/.ctags

--langdef=Go
--langmap=Go:.go
--regex-Go=/func([ \t]+\([^)]+\))?[ \t]+([a-zA-Z0-9_]+)//d,func/
--regex-Go=/var[ \t]+([a-zA-Z_][a-zA-Z0-9_]+)//d,var/
--regex-Go=/type[ \t]+([a-zA-Z_][a-zA-Z0-9_]+)//d,type/

(From http://go-wise.blogspot.com/2011/09/using-ctags-with-go.html)

答案2

得分: 20

--langdef=Go
--langmap=Go:.go
--regex-Go=/func([ \t]+([^)]+))?[ \t]+([a-zA-Z0-9_]+)/\2/f,func/
--regex-Go=/var[ \t]+([a-zA-Z_][a-zA-Z0-9_]+)/\1/v,var/
--regex-Go=/type[ \t]+([a-zA-Z_][a-zA-Z0-9_]+)/\1/t,type/
确实可以与ctags 5.8一起使用。与之前的帖子稍有不同,ctags要求在正则表达式行的末尾使用唯一的1个字符类型。因此,/d,func/应该写成/f,func/以直观地表示。这允许ctags区分和识别类型,从而允许使用ctags --go-types=fvt

英文:
--langdef=Go
--langmap=Go:.go
--regex-Go=/func([ \t]+\([^)]+\))?[ \t]+([a-zA-Z0-9_]+)//f,func/
--regex-Go=/var[ \t]+([a-zA-Z_][a-zA-Z0-9_]+)//v,var/
--regex-Go=/type[ \t]+([a-zA-Z_][a-zA-Z0-9_]+)//t,type/

Does 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, allowing ctags --go-types=fvt i.e.

答案3

得分: 5

我看到了你的帖子,尝试了一些工具来找到一个适合这个工作的好工具,尝试了ctags,但最终并不满意。我用Go写了一个叫做'gotags'的程序,用于生成Go代码的ctags文件。它比当前的ctags支持更好,例如,它会标记结构体字段名以及结构体本身的名称。你可以在这里获取它:https://github.com/necro351/gotags。

这是一个很好的简短的Go程序,因为它使用了标准库的解析器,并且除了良好的Go解析和标记之外没有其他额外的功能。只需查看它(或使用go get命令获取它),然后进行go install。另外,如果你有任何关于改进它的建议或想法,请告诉我。

编辑:我是一个积极的Gopher,所以我会随着时间的推移和使用而更新这个工具。

编辑:我不再积极开发Go了。但是我的工具非常简短,基本上可以正常工作,所以它应该“只需工作” Go的ctag数据库

英文:

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" Go的ctag数据库

答案4

得分: 1

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.

答案5

得分: 0

请检查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 Go的ctag数据库

huangapple
  • 本文由 发表于 2011年11月21日 04:13:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/8204367.html
匿名

发表评论

匿名网友

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

确定