Skip to content

Commit 58ea9cb

Browse files
committed
Merge branch 'release/093'
2 parents 8806c79 + ada817b commit 58ea9cb

6 files changed

Lines changed: 99 additions & 6 deletions

File tree

CHANGELOG.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
#### 0.9.3 Mon Jan 12 18:12:05 PST 2026
4+
5+
* Fix sibling module/class nesting in scope parser
6+
37
#### 0.9.2 Sun Jan 11 10:50:34 PST 2026
48

59
* Fix namespace class definition lookup (Foo::Bar)

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
ruby_language_server (0.9.1)
4+
ruby_language_server (0.9.3)
55
activerecord (~> 8.1)
66
amatch
77
bundler
@@ -278,7 +278,7 @@ CHECKSUMS
278278
rubocop-rake (0.7.1) sha256=3797f2b6810c3e9df7376c26d5f44f3475eda59eb1adc38e6f62ecf027cbae4d
279279
rubocop-rspec (3.8.0) sha256=28440dccb3f223a9938ca1f946bd3438275b8c6c156dab909e2cb8bc424cab33
280280
ruby-progressbar (1.13.0) sha256=80fc9c47a9b640d6834e0dc7b3c94c9df37f08cb072b7761e4a71e22cff29b33
281-
ruby_language_server (0.9.1)
281+
ruby_language_server (0.9.3)
282282
securerandom (0.4.1) sha256=cc5193d414a4341b6e225f0cb4446aceca8e50d5e1888743fac16987638ea0b1
283283
shellany (0.0.1) sha256=0e127a9132698766d7e752e82cdac8250b6adbd09e6c0a7fbbb6f61964fedee7
284284
simplecov (0.22.0) sha256=fe2622c7834ff23b98066bb0a854284b2729a569ac659f82621fc22ef36213a5

lib/ruby_language_server/scope_data/base.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ class Base < ActiveRecord::Base
2525
TYPE_VARIABLE => '^'
2626
}.freeze
2727

28-
attr_accessor :type # Type of this scope (module, class, block)
28+
# Return the class_type as a symbol for easier testing
29+
def type
30+
class_type&.to_sym
31+
end
2932

3033
# bar should be closer to Bar than Far. Adding the UPPER version accomplishes this.
3134
scope :with_distance_from, lambda { |word|

lib/ruby_language_server/scope_parser.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def visit_class_node(node)
4141
end_line = node.location.end_line
4242
column = node.location.start_column
4343

44-
scope = push_scope(ScopeData::Scope::TYPE_CLASS, name, line, column, end_line)
44+
scope = push_scope(ScopeData::Scope::TYPE_CLASS, name, line, column, end_line, false)
4545

4646
# Handle superclass
4747
if node.superclass
@@ -60,7 +60,7 @@ def visit_module_node(node)
6060
end_line = node.location.end_line
6161
column = node.location.start_column
6262

63-
push_scope(ScopeData::Scope::TYPE_MODULE, name, line, column, end_line)
63+
push_scope(ScopeData::Scope::TYPE_MODULE, name, line, column, end_line, false)
6464
super
6565
pop_scope
6666
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module RubyLanguageServer
4-
VERSION = '0.9.2'
4+
VERSION = '0.9.3'
55
end

spec/lib/ruby_language_server/scope_parser_spec.rb

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,91 @@ def some_method
167167
assert_equal('item', scope_parser.root_scope.self_and_descendants.last.variables.first.name)
168168
end
169169
end
170+
171+
describe 'sibling modules' do
172+
before do
173+
@parser = RubyLanguageServer::ScopeParser.new(<<-RUBY)
174+
module Foo
175+
module Bar
176+
end
177+
module Baz
178+
end
179+
end
180+
RUBY
181+
end
182+
183+
it 'places sibling modules at the same level' do
184+
foo = @parser.root_scope.children.first
185+
assert_equal('Foo', foo.name)
186+
187+
children = foo.children
188+
assert_equal(2, children.size, "Foo should have 2 children, but has #{children.size}")
189+
190+
bar = children.detect { |c| c.name == 'Bar' }
191+
baz = children.detect { |c| c.name == 'Baz' }
192+
193+
refute_nil(bar, "Bar should be a child of Foo")
194+
refute_nil(baz, "Baz should be a child of Foo")
195+
assert_equal(0, bar.children.size, "Bar should have no children")
196+
end
197+
end
198+
199+
describe 'sibling classes' do
200+
before do
201+
@parser = RubyLanguageServer::ScopeParser.new(<<-RUBY)
202+
module Foo
203+
class Bar
204+
end
205+
class Baz
206+
end
207+
end
208+
RUBY
209+
end
210+
211+
it 'places sibling classes at the same level' do
212+
foo = @parser.root_scope.children.first
213+
assert_equal('Foo', foo.name)
214+
215+
children = foo.children
216+
assert_equal(2, children.size, "Foo should have 2 children, but has #{children.size}")
217+
218+
bar = children.detect { |c| c.name == 'Bar' }
219+
baz = children.detect { |c| c.name == 'Baz' }
220+
221+
refute_nil(bar, "Bar should be a child of Foo")
222+
refute_nil(baz, "Baz should be a child of Foo")
223+
assert_equal(0, bar.children.size, "Bar should have no children")
224+
end
225+
end
226+
227+
describe 'mixed siblings' do
228+
before do
229+
@parser = RubyLanguageServer::ScopeParser.new(<<-RUBY)
230+
module Foo
231+
class Bar
232+
end
233+
module Baz
234+
end
235+
end
236+
RUBY
237+
end
238+
239+
it 'places sibling class and module at the same level' do
240+
foo = @parser.root_scope.children.first
241+
assert_equal('Foo', foo.name)
242+
243+
children = foo.children
244+
assert_equal(2, children.size, "Foo should have 2 children, but has #{children.size}")
245+
246+
bar = children.detect { |c| c.name == 'Bar' }
247+
baz = children.detect { |c| c.name == 'Baz' }
248+
249+
refute_nil(bar, "Bar should be a child of Foo")
250+
refute_nil(baz, "Baz should be a child of Foo")
251+
assert_equal(:class, bar.type, "Bar should be a class")
252+
assert_equal(:module, baz.type, "Baz should be a module")
253+
assert_equal(0, bar.children.size, "Bar should have no children")
254+
end
255+
end
170256
end
171257
end

0 commit comments

Comments
 (0)