ruby-lsp 0.23.22 → 0.23.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 48c7e1cdc0e7f0a31cbc69002bf6a6c3dea0779272757ee40ae90e4199199446
4
- data.tar.gz: 1cd0d4a426ed4b1c44540e9e3344f73623f0ea0193374cab8faa727528474bf2
3
+ metadata.gz: 2079a33c4ec7e87a6b90bcb3cc11eca81e0d2a9c6d591c2fc14b07234b56c60b
4
+ data.tar.gz: 2837a0acd68b11e065236fb3190baee2e358520694710676fe214e125ae74902
5
5
  SHA512:
6
- metadata.gz: ac87c3a6dcc52b2696076d9793b42f03f56a4e0fbe258cc20f09502bbb289f91acccb3593ebfd36d61b5eeb0ec0bc3ab697acc332b61889fd256db2600029eca
7
- data.tar.gz: be146b667f656ddb1103756a4cf79bd294981fa5f3d0cebc38e44498168799b14941c1768e9f030e80d4f4f7e8c4e4b0107e9cbaf694184ddc037824a05a2f1f
6
+ metadata.gz: fd82d565032cf65414ea926313dfbb7be1c5a21c1d49f9191ed6b9d3c6f4d28458db21f78f14d37af03b84223dc40e4d8cb4c24a1a4a754359757048d84e930a
7
+ data.tar.gz: 48c1dd2271b23e585c37a941db30729d727ceaffb7c12c1b3f806a138834192b9073df72c83bec48a7015bad7d2b109e08f591dc0a69767c39a30c8a6bd96c94
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.23.22
1
+ 0.23.23
@@ -41,8 +41,20 @@ module RubyLsp
41
41
 
42
42
  #: (Prism::ClassNode) -> void
43
43
  def on_class_node_leave(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
44
+ @spec_group_id_stack.pop
44
45
  super
46
+ end
47
+
48
+ #: (Prism::ModuleNode) -> void
49
+ def on_module_node_enter(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
50
+ @spec_group_id_stack << nil
51
+ super
52
+ end
53
+
54
+ #: (Prism::ModuleNode) -> void
55
+ def on_module_node_leave(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
45
56
  @spec_group_id_stack.pop
57
+ super
46
58
  end
47
59
 
48
60
  #: (Prism::CallNode) -> void
@@ -61,6 +73,12 @@ module RubyLsp
61
73
  def on_call_node_leave(node)
62
74
  return unless node.name == :describe && !node.receiver
63
75
 
76
+ current_group = @spec_group_id_stack.last
77
+ return unless current_group.is_a?(DescribeGroup)
78
+
79
+ description = extract_description(node)
80
+ return unless description && current_group.id.end_with?(description)
81
+
64
82
  @spec_group_id_stack.pop
65
83
  end
66
84
 
@@ -76,6 +94,8 @@ module RubyLsp
76
94
  return unless description
77
95
 
78
96
  parent = latest_group
97
+ return unless parent
98
+
79
99
  id = case parent
80
100
  when Requests::Support::TestItem
81
101
  "#{parent.id}::#{description}"
@@ -135,26 +155,50 @@ module RubyLsp
135
155
  end
136
156
  end
137
157
 
138
- #: -> (Requests::Support::TestItem | ResponseBuilders::TestCollection)
158
+ #: -> (Requests::Support::TestItem | ResponseBuilders::TestCollection)?
139
159
  def latest_group
160
+ # If we haven't found anything yet, then return the response builder
140
161
  return @response_builder if @spec_group_id_stack.compact.empty?
162
+ # If we found something that isn't a group last, then we're inside a random module or class, but not a spec
163
+ # group
164
+ return unless @spec_group_id_stack.last
141
165
 
142
- first_class_index = @spec_group_id_stack.rindex { |i| i.is_a?(ClassGroup) } || 0
143
- first_class = @spec_group_id_stack[0] #: as !nil
144
- item = @response_builder[first_class.id] #: as !nil
166
+ # Specs using at least one class as a group require special handling
167
+ closest_class_index = @spec_group_id_stack.rindex { |i| i.is_a?(ClassGroup) }
145
168
 
146
- # Descend into child items from the beginning all the way to the latest class group, ignoring describes
147
- @spec_group_id_stack[1..first_class_index] #: as !nil
148
- .each do |group|
149
- next unless group.is_a?(ClassGroup)
169
+ if closest_class_index
170
+ first_class_index = @spec_group_id_stack.index { |i| i.is_a?(ClassGroup) } #: as !nil
171
+ first_class = @spec_group_id_stack[first_class_index] #: as !nil
172
+ item = @response_builder[first_class.id] #: as !nil
150
173
 
151
- item = item[group.id] #: as !nil
174
+ # Descend into child items from the beginning all the way to the latest class group, ignoring describes
175
+ @spec_group_id_stack[first_class_index + 1..closest_class_index] #: as !nil
176
+ .each do |group|
177
+ next unless group.is_a?(ClassGroup)
178
+
179
+ item = item[group.id] #: as !nil
180
+ end
181
+
182
+ # From the class forward, we must take describes into account
183
+ @spec_group_id_stack[closest_class_index + 1..] #: as !nil
184
+ .each do |group|
185
+ next unless group
186
+
187
+ item = item[group.id] #: as !nil
188
+ end
189
+
190
+ return item
152
191
  end
153
192
 
154
- # From the class forward, we must take describes into account
155
- @spec_group_id_stack[first_class_index + 1..] #: as !nil
193
+ # Specs only using describes
194
+ first_group = @spec_group_id_stack.find { |i| i.is_a?(DescribeGroup) }
195
+ return unless first_group
196
+
197
+ item = @response_builder[first_group.id] #: as !nil
198
+
199
+ @spec_group_id_stack[1..] #: as !nil
156
200
  .each do |group|
157
- next unless group
201
+ next unless group.is_a?(DescribeGroup)
158
202
 
159
203
  item = item[group.id] #: as !nil
160
204
  end
@@ -92,7 +92,7 @@ module RubyLsp
92
92
  #: (String, Hash[String, Hash[Symbol, untyped]]) -> String
93
93
  def handle_minitest_groups(file_path, groups_and_examples)
94
94
  regexes = groups_and_examples.flat_map do |group, info|
95
- examples = info[:examples].map { |e| e.gsub(/test_\d{4}/, "test_\\d{4}") }
95
+ examples = info[:examples].map { |e| Shellwords.escape(e).gsub(/test_\d{4}/, "test_\\d{4}") }
96
96
  group_regex = Shellwords.escape(group).gsub(
97
97
  Shellwords.escape(TestDiscovery::DYNAMIC_REFERENCE_MARKER),
98
98
  ".*",
@@ -18,13 +18,15 @@ module RubyLsp
18
18
  end
19
19
  end
20
20
 
21
- #: (GlobalState global_state, URI::Generic uri, Prism::Dispatcher dispatcher) -> void
22
- def initialize(global_state, uri, dispatcher)
21
+ #: (GlobalState, RubyDocument | ERBDocument, Prism::Dispatcher) -> void
22
+ def initialize(global_state, document, dispatcher)
23
23
  @response_builder = ResponseBuilders::CollectionResponseBuilder
24
24
  .new #: ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens]
25
25
  super()
26
26
 
27
+ @document = document
27
28
  @test_builder = ResponseBuilders::TestCollection.new #: ResponseBuilders::TestCollection
29
+ uri = document.uri
28
30
 
29
31
  if global_state.enabled_feature?(:fullTestDiscovery)
30
32
  Listeners::TestStyle.new(@test_builder, global_state, dispatcher, uri)
@@ -45,6 +47,7 @@ module RubyLsp
45
47
  # @override
46
48
  #: -> Array[Interface::CodeLens]
47
49
  def perform
50
+ @document.cache_set("rubyLsp/discoverTests", @test_builder.response)
48
51
  @response_builder.response + @test_builder.code_lens
49
52
  end
50
53
  end
@@ -512,12 +512,12 @@ module RubyLsp
512
512
  @global_state.index.handle_change(uri) do |index|
513
513
  index.delete(uri, skip_require_paths_tree: true)
514
514
  RubyIndexer::DeclarationListener.new(index, dispatcher, parse_result, uri, collect_comments: true)
515
- code_lens = Requests::CodeLens.new(@global_state, uri, dispatcher)
515
+ code_lens = Requests::CodeLens.new(@global_state, document, dispatcher)
516
516
  dispatcher.dispatch(parse_result.value)
517
517
  end
518
518
  end
519
519
  else
520
- code_lens = Requests::CodeLens.new(@global_state, uri, dispatcher)
520
+ code_lens = Requests::CodeLens.new(@global_state, document, dispatcher)
521
521
  dispatcher.dispatch(parse_result.value)
522
522
  end
523
523
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lsp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.22
4
+ version: 0.23.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify