Skip to content

Add completion for namespace access#595

Merged
vinistock merged 1 commit intomainfrom
02-24-add_namespace_access_completion
Feb 25, 2026
Merged

Add completion for namespace access#595
vinistock merged 1 commit intomainfrom
02-24-add_namespace_access_completion

Conversation

@vinistock
Copy link
Member

@vinistock vinistock commented Feb 24, 2026

This PR implements completion candidates for namespace access (e.g.: Foo::). This scenario returns all constants and singleton methods accessible in the ancestor chain.

Note: there's an interesting behaviour in Ruby concerning inherited constants from Object and forward. They are not available when accessing namespaces even if present in the ancestor chain.

For example:

class Foo
end

Foo::String

You would expect Foo::String to be valid. Foo inherits from Object and String belongs to Object. However, Ruby actually cuts the ancestor chain short and does not include inherited constants for ancestor after Object. This is captured in the implementation and in tests.

Copy link
Member Author

vinistock commented Feb 24, 2026

@vinistock vinistock force-pushed the 02-24-add_namespace_access_completion branch 2 times, most recently from f3659df to 8f18607 Compare February 24, 2026 19:29
@vinistock vinistock self-assigned this Feb 24, 2026
@vinistock vinistock changed the title Add exported RBI types Add completion for namespace access Feb 24, 2026
@vinistock vinistock marked this pull request as ready for review February 24, 2026 19:36
@vinistock vinistock requested a review from a team as a code owner February 24, 2026 19:36
@vinistock vinistock force-pushed the 02-24-add_namespace_access_completion branch from 8f18607 to e1f424a Compare February 24, 2026 22:03
@vinistock vinistock force-pushed the 02-24-add_namespace_access_completion branch from e1f424a to 979565e Compare February 24, 2026 22:12
@vinistock vinistock force-pushed the 02-24-add_namespace_access_completion branch from 979565e to ad6d894 Compare February 25, 2026 14:37
@vinistock vinistock enabled auto-merge February 25, 2026 14:37
@vinistock vinistock merged commit f16e34c into main Feb 25, 2026
34 of 37 checks passed
@vinistock vinistock deleted the 02-24-add_namespace_access_completion branch February 25, 2026 14:53
if let Some(singleton_id) = namespace.singleton_class() {
let singleton = graph.declarations().get(singleton_id).unwrap().as_namespace().unwrap();

for ancestor in singleton.ancestors() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the singleton method ancestor walk should also stop at Object's singleton class?

The constant collection loop above breaks at Object to avoid surfacing inherited constants (e.g. Foo::String). Singleton methods inherited from Object's singleton (like new, allocate, superclass, etc.) would still be collected here since there's no equivalent cutoff. Is that intentional? If so, a short comment explaining the asymmetry would help.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional because of Ruby semantics. Ruby prohibits you from referencing a constant inherited from Object (a.k.a. a top level level constant).

This crashes:

class Foo
end

# Foo inherits from Object and Object owns String
# but this is not allowed anyway
Foo::String

This is not the case for singleton methods. You can invoke singleton methods defined in Object or higher up the chain. I think the current behaviour does make sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants