ruby-lsp 0.23.21 → 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: 336c4740e2cc0c03bec77c7854065bc9115ed14ab88949d41ae8a8da7d58b1da
4
- data.tar.gz: 0b1ccf86525c8db95beb310c23977353520e0951f7c627199db567c50b8b29f8
3
+ metadata.gz: 2079a33c4ec7e87a6b90bcb3cc11eca81e0d2a9c6d591c2fc14b07234b56c60b
4
+ data.tar.gz: 2837a0acd68b11e065236fb3190baee2e358520694710676fe214e125ae74902
5
5
  SHA512:
6
- metadata.gz: ffb2a4605bf6c3b7e82dde8ca73cd624c22aa16a2cf91569b7b38d06a7d876a932023efa4a4dea1871ca0e5965a923be97b9e870f2fd9f0b36d70d354213e9ea
7
- data.tar.gz: e488ffda15f9d7a0549294d70f607c09620144ff3a1fea3441d834c3c2db06cf691997005c357cffcf596b4e41e83599111c48da07d92ea26bde293ae6edde0a
6
+ metadata.gz: fd82d565032cf65414ea926313dfbb7be1c5a21c1d49f9191ed6b9d3c6f4d28458db21f78f14d37af03b84223dc40e4d8cb4c24a1a4a754359757048d84e930a
7
+ data.tar.gz: 48c1dd2271b23e585c37a941db30729d727ceaffb7c12c1b3f806a138834192b9073df72c83bec48a7015bad7d2b109e08f591dc0a69767c39a30c8a6bd96c94
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.23.21
1
+ 0.23.23
@@ -103,7 +103,7 @@ module RubyIndexer
103
103
  #: (RBS::AST::Members::MethodDefinition member, Entry::Namespace owner) -> void
104
104
  def handle_method(member, owner)
105
105
  name = member.name.name
106
- uri = URI::Generic.from_path(path: member.location.buffer.name)
106
+ uri = URI::Generic.from_path(path: member.location.buffer.name.to_s)
107
107
  location = to_ruby_indexer_location(member.location)
108
108
  comments = comments_to_string(member)
109
109
 
@@ -267,7 +267,7 @@ module RubyIndexer
267
267
 
268
268
  #: (RBS::AST::Members::Alias member, Entry::Namespace owner_entry) -> void
269
269
  def handle_signature_alias(member, owner_entry)
270
- uri = URI::Generic.from_path(path: member.location.buffer.name)
270
+ uri = URI::Generic.from_path(path: member.location.buffer.name.to_s)
271
271
  comments = comments_to_string(member)
272
272
 
273
273
  entry = Entry::UnresolvedMethodAlias.new(
@@ -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
@@ -44,7 +44,7 @@ module RubyLsp
44
44
  # If all of the children of the current test group are other groups, then there's no need to add it to the
45
45
  # aggregated examples
46
46
  unless children.any? && children.all? { |child| child[:tags].include?("test_group") }
47
- aggregated_tests[path][item[:label]] = { tags: tags, examples: [] }
47
+ aggregated_tests[path][item[:id]] = { tags: tags, examples: [] }
48
48
  end
49
49
  else
50
50
  class_name, method_name = item[:id].split("#")
@@ -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]
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
  ".*",
@@ -197,6 +197,18 @@ module RubyLsp
197
197
  super
198
198
  end
199
199
 
200
+ #: (Prism::ModuleNode node) -> void
201
+ def on_module_node_enter(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
202
+ @parent_stack << nil
203
+ super
204
+ end
205
+
206
+ #: (Prism::ModuleNode node) -> void
207
+ def on_module_node_leave(node) # rubocop:disable RubyLsp/UseRegisterWithHandlerMethod
208
+ @parent_stack.pop
209
+ super
210
+ end
211
+
200
212
  #: (Prism::DefNode node) -> void
201
213
  def on_def_node_enter(node)
202
214
  return if @visibility_stack.last != :public
@@ -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
 
@@ -30,6 +30,30 @@ module RubyLsp
30
30
  end
31
31
  end
32
32
 
33
+ # This patch is here to prevent other gems from overriding or adding more Minitest reporters. Otherwise, they may
34
+ # break the integration between the server and extension
35
+ module PreventReporterOverridePatch
36
+ @lsp_reporters = [] #: Array[Minitest::AbstractReporter]
37
+
38
+ class << self
39
+ #: Array[Minitest::AbstractReporter]
40
+ attr_accessor :lsp_reporters
41
+ end
42
+
43
+ # Patch the writer to prevent replacing the entire array
44
+ #: (untyped) -> void
45
+ def reporters=(reporters)
46
+ # Do nothing. We don't want other gems to override our reporter
47
+ end
48
+
49
+ # Patch the reader to prevent appending more reporters. This method always returns a temporary copy of the real
50
+ # reporters so that if any gem mutates it, it continues to return the original reporters
51
+ #: -> Array[untyped]
52
+ def reporters
53
+ PreventReporterOverridePatch.lsp_reporters.dup
54
+ end
55
+ end
56
+
33
57
  class MinitestReporter < Minitest::AbstractReporter
34
58
  class << self
35
59
  #: (Hash[untyped, untyped]) -> void
@@ -45,6 +69,8 @@ module RubyLsp
45
69
 
46
70
  # Add the JSON RPC reporter
47
71
  reporters << MinitestReporter.new
72
+ PreventReporterOverridePatch.lsp_reporters = reporters
73
+ Minitest.reporter.class.prepend(PreventReporterOverridePatch)
48
74
  end
49
75
  end
50
76
 
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.21
4
+ version: 0.23.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
@@ -52,7 +52,7 @@ dependencies:
52
52
  version: '3'
53
53
  - - "<"
54
54
  - !ruby/object:Gem::Version
55
- version: '4'
55
+ version: '5'
56
56
  type: :runtime
57
57
  prerelease: false
58
58
  version_requirements: !ruby/object:Gem::Requirement
@@ -62,7 +62,7 @@ dependencies:
62
62
  version: '3'
63
63
  - - "<"
64
64
  - !ruby/object:Gem::Version
65
- version: '4'
65
+ version: '5'
66
66
  - !ruby/object:Gem::Dependency
67
67
  name: sorbet-runtime
68
68
  requirement: !ruby/object:Gem::Requirement