Support array and inline-def arguments to private_class_method#782
Merged
alexcrocha merged 1 commit intoMay 8, 2026
Merged
Conversation
Contributor
Author
This stack of pull requests is managed by Graphite. Learn more about stacking. |
This was referenced May 5, 2026
d041f67 to
e17bd05
Compare
299b305 to
0196acc
Compare
cd8c5c3 to
2ba7006
Compare
0196acc to
4ee8994
Compare
2ba7006 to
48f55ed
Compare
4ee8994 to
c476601
Compare
48f55ed to
aa3c92e
Compare
aa3c92e to
94e1421
Compare
st0012
approved these changes
May 8, 2026
vinistock
approved these changes
May 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Part of #89 and follows #781. With the basic call shape and resolution wired up, this PR extends the indexer to recognize the two other argument shapes Ruby accepts for
private_class_method/public_class_method:Both are common in Ruby code and already supported by ruby-lsp. Parity matters because ruby-lsp's indexing is migrating to Rubydex. Without this PR, these forms silently report the wrong visibility downstream.
Inline def synthesizes a visibility def by name
For
private_class_method def self.foo; endthe indexer extracts the def's name, builds aMethodVisibilityDefinitionfor it with the singleton flag, then visits theDefNodeso theMethodDefinitionis indexed normally. At resolution time the visibility def attaches to the resulting declaration through the existing fully-qualified-name lookup, so no new "inline" definition kind and no new resolution arm are needed. The same path handlesdef self.xnested inside the array form.A receiverless
def(private_class_method [def x; end]orprivate_class_method def x; end) is a coding error: the def isn't a singleton method, so the call doesn't apply to it. We diagnose specifically (`private_class_method` requires a singleton method definition) and still visit theDefNodeso it's indexed.Sole-arg guard for the array form
private_class_method [:a]works at runtime because Ruby unwraps a sole array argument;private_class_method [:a], :bdoesn't. The match arm guards onarg_count == 1to mirror that. A multi-arg call with an array falls through to a separate arm with a tailored diagnostic (`private_class_method` array argument must be the only argument).Why
attr_*arguments get their own diagnosticprivate attr_reader(:foo)works for instance methods becauseattr_readerreturns the names array andprivateconsumes it.private_class_method attr_reader(:foo)doesn't:attr_readerdefines instance methods, so the names don't exist on the singleton, and applying class-method visibility to them is meaningless. Common enough confusion to call out specifically rather than collapse into a generic "non-literal argument" message.Continue past invalid args, in both loops
Inherited from #780 and extended here to array elements: a bad arg or element produces a diagnostic but the loop keeps going.
private_class_method [:a, SOME_CONST, :c]indexes:aand:cand diagnosesSOME_CONST.private_class_method [:a], :bdiagnoses the array-not-sole-arg case and still indexes:b. IDEs see partial-valid code constantly during editing; halting on the first bad arg would discard intelligence the user can still benefit from.In this PR
ArrayNode(sole-arg) withSymbolNode,StringNode, andDefNodeelementsDefNodeas a top-level argument; reject receiverlessdefwith a specific diagnosticattr_*arguments and array-not-sole-arg with tailored messagescreate_method_visibility_definition_from_namehelper so DefNode and Symbol/String paths share definition construction