-
Notifications
You must be signed in to change notification settings - Fork 154
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
Track method's visibility during indexing #2093
Conversation
b5df983
to
563477c
Compare
super(name, file_path, location, comments) | ||
def initialize(name, file_path, location, comments, visibility, owner) # rubocop:disable Metrics/ParameterLists | ||
super(name, file_path, location, comments, visibility) | ||
@visibility = visibility |
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 visibility is already set on the parent, we don't have to set it here.
782fe10
to
d1e165a
Compare
@vinistock I've changed the way visibility is set on entries and reduced the amount of changes needed. |
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 agree with Alex. I would reduce the indirection in favour of more direct code.
This commit supports visibility tracking for methods in the index by: - Adding a visibility field to the Member entry, which is a superclass of Accessor, Method, and Alias. - In the DeclarationListener, create a nested stack structure to track the visibility of the current scope.
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 is great! 🎉
Motivation
Closes #1941
Implementation
Nested stack
Every namespace will have its own visibility stack, for example:
And at each level (scope), we simply push new visibility to its stack whenever we see a modifier.
The only exception is when we face
private def foo; end
, which will pop the stack when we leave the declaration.I chose a different data structure than test
CodeLens
's because it assumes methods are always inside a class, which would create a problem here. And I also feel the way it swaps visibilities is harder to understand than the nested stack I use here.One drawback of this design is that if one scope level has many visibility modifiers, it'd create a big visibility stack at that level, like:
However, I think it's an edge case that we can ignore in order to get a simpler implementation.
Automated Tests
I added 2 new test cases for this change.
Manual Tests