Skip to content

Conversation

@kwerle
Copy link
Owner

@kwerle kwerle commented Jan 29, 2026

No description provided.

@kwerle kwerle requested a review from Copilot January 29, 2026 06:05
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances constant lookup functionality in the ProjectManager to properly handle namespaced constants (e.g., Foo::BAR, Foo::Baz::QUUX). The changes enable "go to definition" to work correctly when clicking on constants within namespace chains.

Changes:

  • Refactored possible_definitions method to analyze namespace chains and identify class/module boundaries
  • Updated project_definitions_for to support hierarchical scope searching with parent scopes
  • Added helper methods find_scope_by_path and constant_name? for improved constant detection

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
lib/ruby_language_server/project_manager.rb Implements namespace-aware constant lookup logic with scope chain traversal
spec/lib/ruby_language_server/project_manager_spec.rb Adds comprehensive test coverage for namespaced constant lookups

Comment on lines +386 to +388
# Position on "BAR" in "Foo::BAR" (line 9, character 10)
# The line is: "puts Foo::BAR"
position = OpenStruct.new(line: 9, character: 10)
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

The comment states the target line is line 9, but the code being tested shows puts Foo::BAR on line 14 of the heredoc (counting from line 0 for module Foo). The line number in the position should match the actual line in the test file content.

Copilot uses AI. Check for mistakes.
Comment on lines +398 to +399
# Position on "QUUX" in "Foo::Baz::QUUX" (line 10, character 16)
position = OpenStruct.new(line: 10, character: 16)
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

The comment indicates line 10, but puts Foo::Baz::QUUX appears on line 15 of the heredoc. This mismatch will cause the test to target the wrong line.

Suggested change
# Position on "QUUX" in "Foo::Baz::QUUX" (line 10, character 16)
position = OpenStruct.new(line: 10, character: 16)
# Position on "QUUX" in "Foo::Baz::QUUX" (line 15, character 16)
position = OpenStruct.new(line: 15, character: 16)

Copilot uses AI. Check for mistakes.
end

it 'finds module definition when clicking on Foo in Foo::BAR' do
# Position on "Foo" in "Foo::BAR" (line 9, character 5)
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

Similar to the previous issues, this comment references line 9 but should reference line 14 where puts Foo::BAR is located in the test code.

Suggested change
# Position on "Foo" in "Foo::BAR" (line 9, character 5)
# Position on "Foo" in "Foo::BAR" (line 14, character 5)

Copilot uses AI. Check for mistakes.
scope_path_parts = context[rightmost_class_index..-2]

if scope_path_parts.empty?
# This shouldn't happen, but handle it gracefully
Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

The comment states 'This shouldn't happen' but the code handles it. If this truly should never occur, consider raising an error or adding logging to track if this case is ever hit, which would help identify bugs in the namespace parsing logic.

Suggested change
# This shouldn't happen, but handle it gracefully
# This shouldn't happen, but handle it gracefully
warn "[RubyLanguageServer::ProjectManager] Unexpected empty scope_path_parts for context=#{context.inspect}, name=#{name.inspect}"

Copilot uses AI. Check for mistakes.
Comment on lines 206 to 207
# Namespace lookup like Foo::Bar or Foo::BAR - no method type filtering

Copy link

Copilot AI Jan 29, 2026

Choose a reason for hiding this comment

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

Line 206 appears to be an orphaned comment with no associated code. Either remove it or clarify what code it relates to, as it currently creates confusion about the control flow.

Suggested change
# Namespace lookup like Foo::Bar or Foo::BAR - no method type filtering

Copilot uses AI. Check for mistakes.
@kwerle kwerle merged commit 60f4635 into develop Jan 29, 2026
3 checks passed
@kwerle kwerle deleted the feature/better_scoping branch January 29, 2026 06:11
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.

2 participants