-
Notifications
You must be signed in to change notification settings - Fork 163
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
Support private_class_method
in the indexer
#2858
base: main
Are you sure you want to change the base?
Conversation
I have signed the CLA! |
Looks great! Another way that private_class_method def self.foo
...
end Can we add a test to verify this doesn't cause anything to break? |
entries = T.must(@index[keyword]) | ||
assert_equal(1, entries.size) | ||
entry = entries.first | ||
assert_equal(Entry::Visibility::PRIVATE, entry.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.
assert_equal(Entry::Visibility::PRIVATE, entry.visibility) | |
assert_predicate(entry.visibility, :private?) |
(I updated some other occurrences in #2859)
entries = T.must(@index[keyword]) | ||
assert_equal(1, entries.size) | ||
entry = entries.first | ||
assert_equal(Entry::Visibility::PRIVATE, entry.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.
assert_equal(Entry::Visibility::PRIVATE, entry.visibility) | |
assert_predicate(entry.visibility, :private?) |
I pushed a commit to the branch below illustrating how an inline https://github.com/Shopify/ruby-lsp/tree/andyw8/def-private-class-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.
I think we actually don't support the inline visibility thing even for other operations, like
private def foo; end
I'm good with moving forward with this PR and addressing that in a separate change.
@vinistock we do: ruby-lsp/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb Lines 333 to 337 in 592495e
(and I verified manually) |
Thanks for the feedback! I'll update the PR over the next couple of days. |
Motivation
Closes #2781
private_class_method
can be used to declare class methods as private. Prior to this PR, this method was not setting the visibility to private for the methods in the arguments.Implementation
My implementation is similar to the
module_function
implementation which was mentioned in the issue.I handled the case where the arguments are
String
s,Symbol
s or anArray
of those. They are mentioned as the valid arguments in the Ruby docs.Automated Tests
I added tests to cover
private_class_method
being passed a combination orString
s andSymbol
s or anArray
ofString
s andSymbol
s.Manual Tests
In this example,
foo
does not get suggested butbar
does.