Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 30, 2025

RSpec let and let! variable declarations were not being captured by the scope parser, preventing code completion and navigation for these variables in test files.

Changes

  • Added on_let_command handler in RspecCommands module to extract variable names from let(:name) syntax and register them in the current scope
  • Added let! support via method_missing to handle the eager evaluation variant (method names with ! require special handling)
  • Added test coverage for both let and let! variables in top-level and nested describe/context blocks

Example

describe UserController do
  let(:user) { User.create(name: 'Test') }        # Now captured as variable 'user'
  let!(:admin) { User.create(admin: true) }       # Now captured as variable 'admin'
  
  context 'when authenticated' do
    let(:token) { 'abc123' }                      # Captured in nested scope
    
    it 'returns users' do
      expect(user).to be_present                  # Variables available for completion
    end
  end
end

Variables are scoped within their containing describe/context blocks, matching RSpec's scoping semantics.

Original prompt

This section details on the original issue you should resolve

<issue_title>rspec 'let' variables should show up</issue_title>
<issue_description>In rspec tests, 'let' variables should show up as variables for the appropriate scope</issue_description>

<agent_instructions>Make sure to add this to the RspecCommands</agent_instructions>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits December 30, 2025 23:57
Co-authored-by: kwerle <23320+kwerle@users.noreply.github.com>
Co-authored-by: kwerle <23320+kwerle@users.noreply.github.com>
Co-authored-by: kwerle <23320+kwerle@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix visibility of 'let' variables in RSpec tests Add RSpec 'let' and 'let!' variable capture to scope parser Dec 31, 2025
Copilot AI requested a review from kwerle December 31, 2025 00:05
…kwerle/ruby_language_server into copilot/fix-rspec-let-variables-display
end

# let! is an eager version of let that is evaluated immediately
def method_missing(method_name, *args, &block)
Copy link
Owner

Choose a reason for hiding this comment

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

Just make this an alias of on_let_command.

end
end

def respond_to_missing?(method_name, include_private = false)
Copy link
Owner

Choose a reason for hiding this comment

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

And this should no longer be needed?

@kwerle kwerle marked this pull request as ready for review December 31, 2025 00:40
@kwerle kwerle merged commit 67cb24d into develop Dec 31, 2025
3 checks passed
@kwerle kwerle deleted the copilot/fix-rspec-let-variables-display branch December 31, 2025 00:40
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.

rspec 'let' variables should show up

2 participants