tmm1 / ripper-tags

fast, accurate ctags generator for ruby source code using Ripper
MIT License
550 stars 43 forks source link

Parser should pickup `class_eval` definations #101

Closed praveendhawan closed 4 years ago

praveendhawan commented 4 years ago
RipperTags::Parser.extract("module Test\n Myclass.class_eval do\n end\n end", "app/models/my_class_test.rb")

Is it possible to extract Myclass for tags? I am facing this issue as Myclass is defined in gem and I am overriding it in my codebase. Is there a way to add these entries to tags so that it generates tags for my_class_test.rb file.

I tried it with Ruby Ripper and it just ignores class_evals.

mislav commented 4 years ago

So within the class_eval do ... end block you have some method definitions that you want to be picked up, right?

I suspect this is the same issue as https://github.com/tmm1/ripper-tags/issues/31, please close if true

praveendhawan commented 4 years ago

no, so the above ripper command output this -

[{:kind=>"module", :line=>1, :language=>"Ruby", :path=>"app/models/my_class_test.rb", :pattern=>"module Test", :full_name=>"Test", :name=>"Test"}]

I want it also output a tag for Myclass and also for what's defined inside. So its a bit different than #31 .

praveendhawan commented 4 years ago

So correct or expected output will be

[{:kind=>"module", :line=>1, :language=>"Ruby", :path=>"app/models/my_class_test.rb", :pattern=>"module Test", :full_name=>"Test", :name=>"Test"}, {:kind=>"class", :line=>2, :language=>"Ruby", :path=>"app/models/my_class_test.rb", :pattern=>" class Myclass", :full_name=>"Test::Myclass", :name=>"Myclass", :class=>"Test"}]
mislav commented 4 years ago

I want it also output a tag for Myclass

I don't think we will do that. We only output tags for locations of definitions. At the place where you did Myclass.class_eval, you did not define it, you just extended it.

praveendhawan commented 4 years ago

@mislav The class is defined in a gem. For eg. Spree. The recommended way to override the classes is to create a decorator file and do class eval or do something like this - https://guides.spreecommerce.org/developer/customization/logic.html

mislav commented 4 years ago

The class is defined in a gem.

I see. Then the tag should ideally point to the location within the gem where the class is actually located, no? By default, ripper-tags doesn't scan your gems, but you can instruct it to do so by supplying the gem paths explicitly. See https://github.com/tmm1/ripper-tags/issues/91#issuecomment-495987359

praveendhawan commented 4 years ago

ok, thanks @mislav. I guess we can close it.