Do you know an alternative ctags generator for Ruby
Asked Answered
N

5

20

Exumerant Ctags does not work well with Ruby, you can see there are many hacks in the ruby.c code and basically it fails recognizing many cases. One of the most important is this bit:

class SomeModule::SomeClass
end

Ctags generates:

SomeModule  someclass.rb  /^class SomeModule::SomeClass$/;"  c

which is wrong. The correct and expected entry is:

SomeClass  someclass.rb  /^class SomeModule::SomeClass$/;"  c

This is very limiting. There are some patches for ctags available which does not work, e.g. https://github.com/xtao/overlay/blob/master/dev-util/ctags/files/ctags-5.5.4-ruby-classes.patch but looking on the ctags ruby codebase, this really needs complete rewrite.

So I have been playing with other option which is https://github.com/rdoc/rdoc-tags which works nicer, but it is slow. I mean really SLOW. Generating tags on my project is 2 seconds with ctags but one hour with this tool. Really.

I found one old project that was parsing Ruby on it's own and generating tags, but it was only for Ruby 1.8. It was slower than ctags, but not that bad.

So I am searching for some alternatives. Do you know about any other working ruby ctags generators which give you proper output and are fast?

Thanks!

Edit: I have found very nice project that works with Ruby 1.9+ and is accurate and fast. I recommend it:

https://github.com/tmm1/ripper-tags

Nostology answered 27/6, 2013 at 8:54 Comment(2)
Or maybe if you know fast and working Ruby parser|lexer that is easy to use so I can write my own tags generator. Should work with Ruby 1.8-2.0.Nostology
Side note about using class SomeModule::SomeClass : it does not create a lexcical scope with SomeModule as parent, you should avoid it -- see #15120224Pizza
D
17

Exuberant ctags out of the box doesn’t do a number of useful things:

  • It doesn’t deal with:

    module A::B
    
  • It doesn’t tag (at least some of) the “operator” methods like ‘==’

  • It doesn’t support qualified tags, —type=+

  • It doesn’t output tags for constants or attributes.

Patch available, but it is only for version 5.5 and does not work anymore.

Other projects:

Source

Docent answered 27/6, 2013 at 8:59 Comment(3)
Yeah, I saw this, but I am unable to find this particular patch. I only have the one for 5.5 version which does not work at all.Nostology
I have got rdoc-tags. I have added the link. Check it out.Docent
Thanks for the link, I already tried that and its slow as hell. E.g. parsing "puppet" project = 1 hour. :-(Nostology
N
19

Ripper-tags effort does solve everything described here. It is based on official Ruby parser which is also quite fast. https://github.com/tmm1/ripper-tags

gem install ripper-tags
cd your_project/
ripper-tags -R

It does also support Emacs as well.

Nostology answered 27/6, 2013 at 9:10 Comment(3)
Ok waiting for more recommendations, but I am pretty happy with ripper-tags. I will accept my own answer just not to confuse readers. :-DNostology
ripper-tags too doesn't index nested modules: github.com/tmm1/ripper-tags/issues/48Ima
Yay! Recently ripper-tags added support for nested / constants github.com/tmm1/ripper-tags/pull/44Ima
D
17

Exuberant ctags out of the box doesn’t do a number of useful things:

  • It doesn’t deal with:

    module A::B
    
  • It doesn’t tag (at least some of) the “operator” methods like ‘==’

  • It doesn’t support qualified tags, —type=+

  • It doesn’t output tags for constants or attributes.

Patch available, but it is only for version 5.5 and does not work anymore.

Other projects:

Source

Docent answered 27/6, 2013 at 8:59 Comment(3)
Yeah, I saw this, but I am unable to find this particular patch. I only have the one for 5.5 version which does not work at all.Nostology
I have got rdoc-tags. I have added the link. Check it out.Docent
Thanks for the link, I already tried that and its slow as hell. E.g. parsing "puppet" project = 1 hour. :-(Nostology
L
4

Add following to your ~/.ctags

--regex-ruby=/(^|;)[ \t]*(class|module)[ \t]+([A-Z][[:alnum:]_]+(::[A-Z][[:alnum:]_]+)+)/\3/c,class,constant/

So you can:

  • deal with: module A::B

See more here: https://github.com/bltavares/dot-files/blob/master/ctags

Liaotung answered 1/2, 2016 at 8:3 Comment(3)
did you write that regex yourself ?Audiogenic
No, I copy from the link.Liaotung
Didn't work for me and I've regenerated the tag file with --regex-ruby=/(^|;)[ \t]*(class|module)[ \t]+([A-Z][[:alnum:]_]+(::[A-Z][[:alnum:]_]+)+)/\3/c,class,constant/ included on ~/.ctagsBahuvrihi
G
1

A patch is available as of 2013-02

the rspec tag generator will not properly recognize describe blocks that start with semicolor (:some-method), but other than that, it's great.

Genealogy answered 4/9, 2013 at 15:45 Comment(2)
Universal ctags didn't work either: ctags --version Universal Ctags 6.0.0, Copyright (C) 2015-2022 Universal Ctags Team Universal Ctags is derived from Exuberant Ctags. Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert Compiled: Mar 26 2023, 05:37:43 URL: ctags.io Output version: 0.0 Optional compiled features: +wildcards, +regex, +gnulib_fnmatch, +gnulib_regex, +iconv, +option-directory, +xpath, +json, +interactive, +yaml, +case-insensitive-filenames, +packcc, +optscriptBahuvrihi
I tend to use ripper-tags nowGenealogy
T
1

There is also https://github.com/eapache/starscope

It doesn't support the extended tag format (yet) but it does other things such as exporting cscope databases.

Teletype answered 10/1, 2014 at 0:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.