Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you know an alternative ctags generator for Ruby

Tags:

vim

ruby

ctags

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

like image 771
lzap Avatar asked Jun 27 '13 08:06

lzap


3 Answers

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.

like image 180
lzap Avatar answered Nov 07 '22 14:11

lzap


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:

  • https://github.com/tmm1/ripper-tags (best option for Ruby 1.9+)
  • https://rubygems.org/gems/rdoc-tags (very slow but works with 1.8)

Source

like image 17
Jayram Avatar answered Nov 07 '22 13:11

Jayram


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

like image 5
lingceng Avatar answered Nov 07 '22 14:11

lingceng