Do you know an alternative ctags generator for Ruby

寵の児 提交于 2019-11-29 16:43:41

问题


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


回答1:


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




回答2:


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.




回答3:


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




回答4:


A patch is available as of 2013-02

  • https://github.com/fishman/ctags (ctags patch for Ruby, including rspec)

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




回答5:


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.



来源:https://stackoverflow.com/questions/17338779/do-you-know-an-alternative-ctags-generator-for-ruby

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!