Repository navigation
Improve constant lookup in SourceFinder - #871
Conversation
6f71459 to
6c10788
Compare
| elsif parts == [''] # ::ConstName | ||
| Object | ||
| else # ConstPath::ConstName | ||
| eval_receiver_or_owner(parts.join('::')) |
There was a problem hiding this comment.
In this case, the result of this should be the same as eval_receiver_or_owner(signature)? If that's the case, maybe we can store that and use it here?
There was a problem hiding this comment.
If signature == 'A::B::C', parts.join('::') will be 'A::B'
We need to evaluate A::B in current binding and get base = FooBar::A::B (FooBar part depends on binding's Module.nesting)
Now we can find source by calling base.const_source_location('C')
| base = @irb_context.workspace.binding.receiver.yield_self { |r| r.is_a?(Module) ? r : Object } | ||
| file, line = base.const_source_location(signature) | ||
| *parts, name = signature.split('::', -1) | ||
| base = ( |
There was a problem hiding this comment.
nit: I think having these parentheses introduces a new style that didn't exist in this repo before 🤔 ?
There was a problem hiding this comment.
Updated to
a =
if cond
else
endstyle
6c10788 to
7a4714b
Compare
Improve show_source of constant to find const owner more precise.
Constant lookup does not depend on
self, but onModule.nestingIn this test code I added,
X,Y,Z,Arrayare all visible with value == 1Module.nestingis[A::B, A]and lookup order seemsA::B → A → A::B.ancestors → A.ancestors → TOPLEVEL(Object)