-
Notifications
You must be signed in to change notification settings - Fork 7
Fix sibling module/class nesting in scope parser #130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: kwerle <23320+kwerle@users.noreply.github.com>
Co-authored-by: kwerle <23320+kwerle@users.noreply.github.com>
| end | ||
| end | ||
|
|
||
| describe 'sibling modules' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor sibling modules and sibling classes into siblings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored into shared examples to eliminate duplication. Both module and class sibling tests now use the same test logic via shared_examples 'sibling scopes'. (e7b7e94)
Co-authored-by: kwerle <23320+kwerle@users.noreply.github.com>
kwerle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a case where the siblings are different - one a class and one a module.
Co-authored-by: kwerle <23320+kwerle@users.noreply.github.com>
Added test case for mixed siblings under |
| end | ||
|
|
||
| describe 'siblings' do | ||
| shared_examples 'sibling scopes' do |type| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually a minitest. And it is failing. Fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Converted from RSpec syntax (shared_examples, include_examples, let) to proper minitest syntax using before blocks and @parser instance variables. (4d74e6c)
Co-authored-by: kwerle <23320+kwerle@users.noreply.github.com>
kwerle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can refactor "should place sibling class and module at the same level" better than that.
Maybe it would be easier if you just convert the test to a pure minitest file?
Co-authored-by: kwerle <23320+kwerle@users.noreply.github.com>
Refactored using a helper method |
kwerle
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the failing tests.
Co-authored-by: kwerle <23320+kwerle@users.noreply.github.com>
Fixed. The helper method was defined inside the |
Co-authored-by: kwerle <23320+kwerle@users.noreply.github.com>
Fix Module and Class Scope Closing Issue ✓
Problem
Module and class blocks were not properly closed, causing sibling modules/classes to appear nested incorrectly. For example:
Module
Bazwas being placed inside moduleBarinstead of as a sibling.Root Cause
In
scope_parser.rb, thevisit_module_nodeandvisit_class_nodemethods were callingpush_scopewith the defaultclose_siblings=trueparameter, which incorrectly closed or interfered with sibling scopes.Solution
Modified both methods to pass
close_siblings=falsewhen callingpush_scope, aligning their behavior with methods and blocks.Changes Made
push_scopeandclose_sibling_scopesinteractionclose_sibling_scopesTechnical Details
Modified Files:
lib/ruby_language_server/scope_parser.rb: Changedpush_scopecalls invisit_module_node(line 225) andvisit_class_node(line 297) to passfalseforclose_siblingsparameterspec/lib/ruby_language_server/scope_parser_spec.rb: Added comprehensive test cases using proper minitest syntax for sibling modules, sibling classes, and mixed siblings with descriptive error messagesTest Coverage:
beforeblocks and@parserinstance variablesSecurity Summary
No security vulnerabilities were found in the changes.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.