-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace RubyIndexer::Collector with RubyIndexer::DeclarationListener #2008
Conversation
6739fe9
to
9584ebd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, looks good to me. I'm not super happy with the name Listener
, though. Hopefully there's something more descriptive we can use.
@@ -185,9 +185,11 @@ def index_all(indexable_paths: RubyIndexer.configuration.indexables, &block) | |||
sig { params(indexable_path: IndexablePath, source: T.nilable(String)).void } | |||
def index_single(indexable_path, source = nil) | |||
content = source || File.read(indexable_path.full_path) | |||
dispatcher = Prism::Dispatcher.new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to be able to index at the same time that we run semantic highlighting, document symbol and others, then we'll need to receiver the dispatcher as an argument. Maybe we can make it optional with the default of Prism::Dispatcher.new
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I agree with the idea, I prefer leaving this change to the PR where we're actually doing so as it will make the change linked its dependencies. If we do it in this PR, it'd be hard to understand the intention without checking the PR discussions.
This rewrite will give us a few benefits: - We can use the same pattern as we write request listeners, which will make maintenance easier. - It will make some future indexing features easier to implement. With collector, we don't have access to a node's leave events, which makes features like capturing visibility hard to implement. - Since `Prism::Dispatcher` visits all nodes in the AST, we can now collect nodes that are defined unconventionally, like behind conditionals or begin blocks, just by doing the switching. Unfortunately, this change will make indexing slower. In Core, it increases the indexing time from ~32 seconds to ~41 seconds (~28%). But on the other hand, if in the future `Prism::Dispatcher` receives performance improvements, the indexer will benefit automatically from them too.
9584ebd
to
dd4b44f
Compare
Motivation
This rewrite will give us a few benefits:
Prism::Dispatcher
visits all nodes in the AST, we can nowcollect nodes that are defined unconventionally, like behind conditionals
or begin blocks, just by doing the switching.
Unfortunately, this change will make indexing slower. In Core, it increases the indexing time from ~32 seconds to ~41 seconds (~28%). But on the other hand, if in the future
Prism::Dispatcher
receives performance improvements, the indexer will benefit automatically from them too.Implementation
RubyIndexer::DeclarationListener
classPrism::Dispatcher
and register the relevant events,DeclarationListener
can reuse most methods fromCollector
with minor tweaks and renaming.Collector
references withDeclarationListener
.Automated Tests
I added a few simple tests for the newly supported cases.
Manual Tests