質問

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.

役に立ちましたか?

解決

Add the following to ~/.ctags

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

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

他のヒント

--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/

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.

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" :)

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 ;-)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top