Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
f3659df to
8f18607
Compare
8f18607 to
e1f424a
Compare
e1f424a to
979565e
Compare
979565e to
ad6d894
Compare
| if let Some(singleton_id) = namespace.singleton_class() { | ||
| let singleton = graph.declarations().get(singleton_id).unwrap().as_namespace().unwrap(); | ||
|
|
||
| for ancestor in singleton.ancestors() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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::StringThis 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.

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
Objectand forward. They are not available when accessing namespaces even if present in the ancestor chain.For example:
You would expect
Foo::Stringto be valid.Fooinherits fromObjectandStringbelongs toObject. However, Ruby actually cuts the ancestor chain short and does not include inherited constants for ancestor afterObject. This is captured in the implementation and in tests.