lzap
lzap

Reputation: 17173

Do you know an alternative ctags generator for Ruby

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

Upvotes: 20

Views: 7419

Answers (5)

lingceng
lingceng

Reputation: 2425

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

Upvotes: 4

Evan
Evan

Reputation: 6555

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.

Upvotes: 1

New Alexandria
New Alexandria

Reputation: 7334

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.

Upvotes: 1

lzap
lzap

Reputation: 17173

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.

Upvotes: 19

Jayram
Jayram

Reputation: 19588

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

Upvotes: 17

Related Questions