ctag database for Go
Asked Answered
M

5

27

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.

Malindamalinde answered 20/11, 2011 at 20:13 Comment(0)
D
50

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)

Dentate answered 23/11, 2011 at 3:2 Comment(5)
Thank you for the help.. can u please let me know where did u find ver 5.9, or how to install it. Did u get directly from svn? ctags.svn.sourceforge.net/viewvc/ctags/trunk .. thanks againMalindamalinde
I have the one that comes with Ubuntu 11.10Dentate
At this writing, the latest exuberant ctags release on SourceForge is 5.8, and the SVN trunk doesn't have go support. Whatever version you're using, it's definitely not the official codebase.Hervey
I don't know what the author of this post is talking about since there is no version 5.9 and the project officialy doesn't support Go. Supported languages: ctags.sourceforge.net/languages.html Versions: ctags.sourceforge.net/news.html (latest ctags-5.8, 09 Jul 2009).Pyridoxine
Hmm, you're right. Don't know where I got the 5.9 from. FixedDentate
B
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/

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.

Berkman answered 24/8, 2012 at 17:20 Comment(0)
S
6

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

Swisher answered 29/11, 2014 at 6:28 Comment(0)
T
2

universal-ctags supports Go. It's the successor of exuberant-ctags and works perfectly fine. See here for the man pages.

Tibiotarsus answered 25/11, 2022 at 18:59 Comment(0)
B
0

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

Baal answered 21/11, 2011 at 10:47 Comment(1)
I did try all 3, but they are not updated for some time. I may try make them work if there are no other option. Thanks.Malindamalinde

© 2022 - 2024 — McMap. All rights reserved.