Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 2, 2026

Method parameters and local variables were not found during definition lookup because scope_definitions_for only checked the innermost scope repeatedly instead of walking the scope chain.

Root Cause

The while loop incremented check_scope to traverse parent scopes but always queried scope.variables:

while check_scope
  scope.variables.each do |variable|  # Always queries the same scope
    # ...
  end
  check_scope = check_scope.parent
end

This caused lookups to miss variables in the current scope when searching from within nested contexts.

Changes

  • lib/ruby_language_server/project_manager.rb: Changed scope.variables.each to check_scope.variables.each to properly traverse the scope chain
  • spec/lib/ruby_language_server/project_manager_spec.rb: Added test covering parameter shadowing scenario from issue
Original prompt

This section details on the original issue you should resolve

<issue_title>method variables not getting used for definition locating</issue_title>
<issue_description>If you have the following:

class Foo
  def meaningful ...
end

class Bar
  def some_method(meaningful)
    meaningful.do_something
  end
end

When you look for the definition of meaningfujl in some_method, it should find the local declaration. It does not - it only finds the method defined in class Foo.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: kwerle <23320+kwerle@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix method variables not getting used for definition locating Fix scope chain traversal in variable definition lookup Jan 2, 2026
Copilot AI requested a review from kwerle January 2, 2026 02:51
@kwerle kwerle marked this pull request as ready for review January 2, 2026 07:10
@kwerle kwerle merged commit d6e83cc into develop Jan 2, 2026
4 checks passed
@kwerle kwerle deleted the copilot/fix-local-variable-definition-locating branch January 2, 2026 07:10
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.

method variables not getting used for definition locating

2 participants