@@ -167,8 +167,15 @@ def possible_definitions(uri, position)
167167
168168 context = context_at_location ( uri , position )
169169
170- # If context has more than one element it's a method call on a receiver
170+ # If context has more than one element it could be a method call or namespace reference
171171 if context . length > 1
172+ # Check if this is a namespace reference (Foo::Bar) vs method call (Foo.bar)
173+ if namespace_reference? ( uri , position , context )
174+ # Join the context with :: to form the full class/module name
175+ full_name = context . join ( '::' )
176+ return project_definitions_for ( full_name )
177+ end
178+
172179 receiver = context . first
173180 # Determine if it's a class method call (Foo.method) or instance method call (foo.method)
174181 class_method_filter = name != 'initialize'
@@ -206,7 +213,13 @@ def scope_definitions_for(name, scope, uri)
206213 end
207214
208215 def project_definitions_for ( name , class_method_filter = nil )
209- scopes = RubyLanguageServer ::ScopeData ::Scope . where ( name :)
216+ # Check if name contains namespace separator (e.g., "Foo::Bar")
217+ # If so, search by path instead of name
218+ scopes = if name . include? ( '::' )
219+ RubyLanguageServer ::ScopeData ::Scope . where ( path : name )
220+ else
221+ RubyLanguageServer ::ScopeData ::Scope . where ( name :)
222+ end
210223
211224 # Filter by class_method attribute if specified
212225 scopes = scopes . where ( class_method : class_method_filter ) unless class_method_filter . nil?
@@ -219,6 +232,16 @@ def project_definitions_for(name, class_method_filter = nil)
219232
220233 private
221234
235+ # Check if the context represents a namespace reference (Foo::Bar) rather than a method call (Foo.bar)
236+ # Class/module lookups always start with uppercase letters, method calls never do
237+ def namespace_reference? ( _uri , _position , context )
238+ return false if context . length < 2
239+
240+ # If all parts start with uppercase, it's a namespace reference (Foo::Bar)
241+ # If first part is lowercase, it's a method call (foo.bar)
242+ context . all? { |part | /\A [A-Z]/ . match? ( part ) }
243+ end
244+
222245 # Guess if a receiver name is likely a class name based on idiomatic Ruby conventions.
223246 # This is a heuristic and not 100% accurate (e.g., FOO could be a constant holding an instance).
224247 # Returns true for names like "Foo" or "FooBar" (starts with uppercase, has lowercase letters).
0 commit comments