This is actually quite similar to some of the code I've been playing
around with in implementing a F3 - Go to Declaration feature. You may want
to browse through some of the latest checkins on our repository (the code
has mostly been in rdt.core's SelectionEngine).
the approach I'm taking right now is very hacky and doesn't search the
scopes in the right order, but it does work (for the most part). You should
be able to hit F3 on method calls, variables or class/module/constant names
and typically come up with something.
It needs work to:
- handle search the scopes in order (it doesn't work right when a local var
name is used between multiple methods in a class, for example)
- Search the load paths (first, or only them) rather than the project as a
- handle project dependencies
- Probably try to take advantage of the symbol index (that gets built and
updated with the builder incrementally) to get an initial search faster
(rather than a depth first project wide search)
- search via the RubyElement hierarchy rather than by AST nodes. This is a
little confusing in how to explain this, but the RubyElement hierarchy
should respect scopes in using them as the basis for searching, while the
AST nodes have no easy mechanism to do so. We shoudl resolve an AST node to
it RubyElement representation and then use that to find the initial
declaration. Instead we skip from taking the AST node type and name and use
that to find the first matching RubyElement. This is why we fail to
recognize local vars with the same name that are in distinct scopes (say two
I'm guessing this hyperlink feature would share most of the backend code in
resolving the selections and doing the search. I'd greatly appreciate any
help in solidifying this stuff.
When I get home I'll throw this patch into trunk, and you might want to
consider having it hook into the SelectioNEngine/codeassist stuff in
rdt.core. Then we can both tweak that stuff to do the right thing.
On 11/30/06, Werner Schuster (murphee) <werner.schuster@...> wrote:
> Hmm... Charles O.Nutter talking about that RDT clone they're throwing
> together over at Sun:
> Odd, really, that he talks about it eclipsing 'other Ruby IDEs' ...
> where RDT has everything he mentions, like MarkOccurrences, rename
> refactoring (not inline yet), and AutoComplete.
> Granted... one thing was missing: code browsing a la JDT (you know, hold
> down Ctrl and move over a class or method, and it'll turn into a
> hyperlink that'll take to there).
> So there's me thinking: how about I invest an hour and see how far I can
> implement this. To be honest, it took me 1 1/2 hours, but here's a first
> proof of concept of this functionality (I attached the patch against the
> current SVN trunk).