-
Notifications
You must be signed in to change notification settings - Fork 179
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
Index constants #893
Index constants #893
Conversation
|
b8b9d11
to
69f0d22
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.
Looking great!!
end | ||
def add_constant(node) | ||
comments = collect_comments(node) | ||
@index << Index::Entry::Constant.new(fully_qualify_name(node.name), @file_path, node.location, comments) |
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.
Do we not need the same logic for the name here? And why not?
fully_qualified_name = name.start_with?("::") ? name.delete_prefix("::") : fully_qualify_name(name)
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.
Because if there's ::
, either in the middle of as a prefix, it'd be a ConstantPath*
node instead.
).void | ||
end | ||
def add_constant_with_path(node) | ||
name = node.target.location.slice |
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.
This method is almost identical to the other one. Is there a way we can write this to share the same implementation between the two?
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.
ConstantWriteNode
and ConstantPathWriteNode
needs to be indexed differently in 2 places:
- How
name
is retrieved - Whether
::
needs to be handled
Consider these, I prefer having them separated for now instead of checking node type inside the shared method.
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.
We could move the ::
handling inside fully_qualify_name
, which probably fits the responsibility better.
And we can also get the name for the constant with node.location.slice
. It's just a suggestion though, it might allow some cleanup.
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.
I wonder if the ::
prefix should always be deleted in Index#<<
. It seems it's more a concern of the index itself rather than the visitor.
If I was to use an index manually, shouldn't I benefit from this behavior instead of having to reimplement it myself every time?
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.
Yeah, that might be the case. Maybe we can move the handling of the prefix to the index.
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.
Ok, I will open another PR for this as it affects class/module indexing too.
69f0d22
to
856a54d
Compare
).void | ||
end | ||
def add_constant_with_path(node) | ||
name = node.target.location.slice |
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.
We could move the ::
handling inside fully_qualify_name
, which probably fits the responsibility better.
And we can also get the name for the constant with node.location.slice
. It's just a suggestion though, it might allow some cleanup.
856a54d
to
646d2c6
Compare
…d-patch-b823885b92 Bump the minor-and-patch group with 4 updates
Motivation
Having constants in the index would be helpful for both go-to-definition and hover features.
Closes #883
Implementation
Since the goal is to index constants' definitions, I introduced new methods to handle
Constant(Path)WriteNode
andConstant(Path)OperatorOrWriteNode
. Those nodes will be added to the index asRubyIndexer::Index::Constant
with fully qualified names.Automated Tests
I added
lib/ruby_indexer/test/constant_test.rb
for it.Manual Tests