ruby-lsp 0.23.15 → 0.23.17

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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +1 -1
  4. data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +16 -19
  5. data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +0 -3
  6. data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +9 -19
  7. data/lib/ruby_indexer/lib/ruby_indexer/index.rb +33 -69
  8. data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +1 -10
  9. data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +4 -4
  10. data/lib/ruby_indexer/test/index_test.rb +7 -0
  11. data/lib/ruby_indexer/test/method_test.rb +7 -7
  12. data/lib/ruby_indexer/test/rbs_indexer_test.rb +4 -3
  13. data/lib/ruby_indexer/test/test_case.rb +7 -1
  14. data/lib/ruby_lsp/document.rb +7 -10
  15. data/lib/ruby_lsp/erb_document.rb +2 -2
  16. data/lib/ruby_lsp/listeners/completion.rb +8 -8
  17. data/lib/ruby_lsp/listeners/definition.rb +7 -7
  18. data/lib/ruby_lsp/listeners/document_link.rb +7 -10
  19. data/lib/ruby_lsp/listeners/hover.rb +10 -9
  20. data/lib/ruby_lsp/listeners/signature_help.rb +2 -2
  21. data/lib/ruby_lsp/listeners/spec_style.rb +11 -11
  22. data/lib/ruby_lsp/listeners/test_style.rb +15 -10
  23. data/lib/ruby_lsp/rbs_document.rb +2 -2
  24. data/lib/ruby_lsp/requests/code_action_resolve.rb +54 -51
  25. data/lib/ruby_lsp/requests/code_lens.rb +15 -3
  26. data/lib/ruby_lsp/requests/completion.rb +2 -2
  27. data/lib/ruby_lsp/requests/definition.rb +3 -4
  28. data/lib/ruby_lsp/requests/document_highlight.rb +1 -1
  29. data/lib/ruby_lsp/requests/document_link.rb +1 -1
  30. data/lib/ruby_lsp/requests/folding_ranges.rb +1 -1
  31. data/lib/ruby_lsp/requests/go_to_relevant_file.rb +0 -2
  32. data/lib/ruby_lsp/requests/hover.rb +1 -1
  33. data/lib/ruby_lsp/requests/inlay_hints.rb +1 -1
  34. data/lib/ruby_lsp/requests/references.rb +1 -16
  35. data/lib/ruby_lsp/requests/rename.rb +1 -4
  36. data/lib/ruby_lsp/requests/request.rb +2 -1
  37. data/lib/ruby_lsp/requests/selection_ranges.rb +1 -1
  38. data/lib/ruby_lsp/requests/semantic_highlighting.rb +1 -1
  39. data/lib/ruby_lsp/requests/show_syntax_tree.rb +1 -1
  40. data/lib/ruby_lsp/requests/signature_help.rb +1 -1
  41. data/lib/ruby_lsp/requests/support/annotation.rb +1 -1
  42. data/lib/ruby_lsp/requests/support/common.rb +0 -5
  43. data/lib/ruby_lsp/requests/support/source_uri.rb +4 -2
  44. data/lib/ruby_lsp/requests/support/test_item.rb +6 -0
  45. data/lib/ruby_lsp/response_builders/document_symbol.rb +1 -1
  46. data/lib/ruby_lsp/response_builders/test_collection.rb +37 -0
  47. data/lib/ruby_lsp/ruby_document.rb +4 -34
  48. data/lib/ruby_lsp/server.rb +38 -22
  49. data/lib/ruby_lsp/setup_bundler.rb +2 -1
  50. data/lib/ruby_lsp/store.rb +6 -6
  51. data/lib/ruby_lsp/test_reporters/lsp_reporter.rb +43 -4
  52. data/lib/ruby_lsp/utils.rb +55 -2
  53. metadata +1 -1
@@ -13,14 +13,9 @@ module RubyLsp
13
13
  NEW_METHOD_NAME = "new_method"
14
14
 
15
15
  class CodeActionError < StandardError; end
16
-
17
- class Error < ::T::Enum
18
- enums do
19
- EmptySelection = new
20
- InvalidTargetRange = new
21
- UnknownCodeAction = new
22
- end
23
- end
16
+ class EmptySelectionError < CodeActionError; end
17
+ class InvalidTargetRangeError < CodeActionError; end
18
+ class UnknownCodeActionError < CodeActionError; end
24
19
 
25
20
  #: (RubyDocument document, GlobalState global_state, Hash[Symbol, untyped] code_action) -> void
26
21
  def initialize(document, global_state, code_action)
@@ -31,9 +26,9 @@ module RubyLsp
31
26
  end
32
27
 
33
28
  # @override
34
- #: -> (Interface::CodeAction | Error)
29
+ #: -> (Interface::CodeAction)
35
30
  def perform
36
- return Error::EmptySelection if @document.source.empty?
31
+ raise EmptySelectionError, "Invalid selection for refactor" if @document.source.empty?
37
32
 
38
33
  case @code_action[:title]
39
34
  when CodeActions::EXTRACT_TO_VARIABLE_TITLE
@@ -47,26 +42,30 @@ module RubyLsp
47
42
  CodeActions::CREATE_ATTRIBUTE_ACCESSOR
48
43
  create_attribute_accessor
49
44
  else
50
- Error::UnknownCodeAction
45
+ raise UnknownCodeActionError, "Unknown code action: #{@code_action[:title]}"
51
46
  end
52
47
  end
53
48
 
54
49
  private
55
50
 
56
- #: -> (Interface::CodeAction | Error)
51
+ #: -> (Interface::CodeAction)
57
52
  def switch_block_style
58
53
  source_range = @code_action.dig(:data, :range)
59
- return Error::EmptySelection if source_range[:start] == source_range[:end]
54
+ raise EmptySelectionError, "Invalid selection for refactor" if source_range[:start] == source_range[:end]
60
55
 
61
56
  target = @document.locate_first_within_range(
62
57
  @code_action.dig(:data, :range),
63
58
  node_types: [Prism::CallNode],
64
59
  )
65
60
 
66
- return Error::InvalidTargetRange unless target.is_a?(Prism::CallNode)
61
+ unless target.is_a?(Prism::CallNode)
62
+ raise InvalidTargetRangeError, "Couldn't find an appropriate location to place extracted refactor"
63
+ end
67
64
 
68
65
  node = target.block
69
- return Error::InvalidTargetRange unless node.is_a?(Prism::BlockNode)
66
+ unless node.is_a?(Prism::BlockNode)
67
+ raise InvalidTargetRangeError, "Couldn't find an appropriate location to place extracted refactor"
68
+ end
70
69
 
71
70
  indentation = " " * target.location.start_column unless node.opening_loc.slice == "do"
72
71
 
@@ -91,10 +90,10 @@ module RubyLsp
91
90
  )
92
91
  end
93
92
 
94
- #: -> (Interface::CodeAction | Error)
93
+ #: -> (Interface::CodeAction)
95
94
  def refactor_variable
96
95
  source_range = @code_action.dig(:data, :range)
97
- return Error::EmptySelection if source_range[:start] == source_range[:end]
96
+ raise EmptySelectionError, "Invalid selection for refactor" if source_range[:start] == source_range[:end]
98
97
 
99
98
  start_index, end_index = @document.find_index_by_position(source_range[:start], source_range[:end])
100
99
  extracted_source = @document.source[start_index...end_index] #: as !nil
@@ -111,16 +110,20 @@ module RubyLsp
111
110
 
112
111
  closest_statements = node_context.node
113
112
  parent_statements = node_context.parent
114
- return Error::InvalidTargetRange if closest_statements.nil? || closest_statements.child_nodes.compact.empty?
113
+ if closest_statements.nil? || closest_statements.child_nodes.compact.empty?
114
+ raise InvalidTargetRangeError, "Couldn't find an appropriate location to place extracted refactor"
115
+ end
115
116
 
116
117
  # Find the node with the end line closest to the requested position, so that we can place the refactor
117
118
  # immediately after that closest node
118
- closest_node = T.must(closest_statements.child_nodes.compact.min_by do |node|
119
+ closest_node = closest_statements.child_nodes.compact.min_by do |node|
119
120
  distance = source_range.dig(:start, :line) - (node.location.end_line - 1)
120
121
  distance <= 0 ? Float::INFINITY : distance
121
- end)
122
+ end #: as !nil
122
123
 
123
- return Error::InvalidTargetRange if closest_node.is_a?(Prism::MissingNode)
124
+ if closest_node.is_a?(Prism::MissingNode)
125
+ raise InvalidTargetRangeError, "Couldn't find an appropriate location to place extracted refactor"
126
+ end
124
127
 
125
128
  closest_node_loc = closest_node.location
126
129
  # If the parent expression is a single line block, then we have to extract it inside of the one-line block
@@ -151,7 +154,9 @@ module RubyLsp
151
154
  lines = @document.source.lines
152
155
 
153
156
  indentation_line = lines[indentation_line_number]
154
- return Error::InvalidTargetRange unless indentation_line
157
+ unless indentation_line
158
+ raise InvalidTargetRangeError, "Couldn't find an appropriate location to place extracted refactor"
159
+ end
155
160
 
156
161
  indentation = indentation_line[/\A */] #: as !nil
157
162
  .size
@@ -162,7 +167,9 @@ module RubyLsp
162
167
  }
163
168
 
164
169
  line = lines[target_line]
165
- return Error::InvalidTargetRange unless line
170
+ unless line
171
+ raise InvalidTargetRangeError, "Couldn't find an appropriate location to place extracted refactor"
172
+ end
166
173
 
167
174
  variable_source = if line.strip.empty?
168
175
  "\n#{" " * indentation}#{NEW_VARIABLE_NAME} = #{extracted_source}"
@@ -190,10 +197,10 @@ module RubyLsp
190
197
  )
191
198
  end
192
199
 
193
- #: -> (Interface::CodeAction | Error)
200
+ #: -> (Interface::CodeAction)
194
201
  def refactor_method
195
202
  source_range = @code_action.dig(:data, :range)
196
- return Error::EmptySelection if source_range[:start] == source_range[:end]
203
+ raise EmptySelectionError, "Invalid selection for refactor" if source_range[:start] == source_range[:end]
197
204
 
198
205
  start_index, end_index = @document.find_index_by_position(source_range[:start], source_range[:end])
199
206
  extracted_source = @document.source[start_index...end_index] #: as !nil
@@ -206,11 +213,15 @@ module RubyLsp
206
213
  code_units_cache: @document.code_units_cache,
207
214
  )
208
215
  closest_node = node_context.node
209
- return Error::InvalidTargetRange unless closest_node
216
+ unless closest_node
217
+ raise InvalidTargetRangeError, "Couldn't find an appropriate location to place extracted refactor"
218
+ end
210
219
 
211
220
  target_range = if closest_node.is_a?(Prism::DefNode)
212
221
  end_keyword_loc = closest_node.end_keyword_loc
213
- return Error::InvalidTargetRange unless end_keyword_loc
222
+ unless end_keyword_loc
223
+ raise InvalidTargetRangeError, "Couldn't find an appropriate location to place extracted refactor"
224
+ end
214
225
 
215
226
  end_line = end_keyword_loc.end_line - 1
216
227
  character = end_keyword_loc.end_column
@@ -331,7 +342,7 @@ module RubyLsp
331
342
  indentation ? body_content.gsub(";", "\n") : "#{body_content.gsub("\n", ";")} "
332
343
  end
333
344
 
334
- #: -> (Interface::CodeAction | Error)
345
+ #: -> (Interface::CodeAction)
335
346
  def create_attribute_accessor
336
347
  source_range = @code_action.dig(:data, :range)
337
348
 
@@ -349,20 +360,12 @@ module RubyLsp
349
360
  )
350
361
  node = node_context.node
351
362
 
352
- return Error::EmptySelection unless CodeActions::INSTANCE_VARIABLE_NODES.include?(node.class)
363
+ unless CodeActions::INSTANCE_VARIABLE_NODES.include?(node.class)
364
+ raise EmptySelectionError, "Invalid selection for refactor"
365
+ end
353
366
  end
354
367
 
355
- node = T.cast(
356
- node,
357
- T.any(
358
- Prism::InstanceVariableAndWriteNode,
359
- Prism::InstanceVariableOperatorWriteNode,
360
- Prism::InstanceVariableOrWriteNode,
361
- Prism::InstanceVariableReadNode,
362
- Prism::InstanceVariableTargetNode,
363
- Prism::InstanceVariableWriteNode,
364
- ),
365
- )
368
+ node = node #: as Prism::InstanceVariableAndWriteNode | Prism::InstanceVariableOperatorWriteNode | Prism::InstanceVariableOrWriteNode | Prism::InstanceVariableReadNode | Prism::InstanceVariableTargetNode | Prism::InstanceVariableWriteNode # rubocop:disable Layout/LineLength
366
369
 
367
370
  node_context = @document.locate_node(
368
371
  {
@@ -376,20 +379,20 @@ module RubyLsp
376
379
  ],
377
380
  )
378
381
  closest_node = node_context.node
379
- return Error::InvalidTargetRange if closest_node.nil?
382
+ if closest_node.nil?
383
+ raise InvalidTargetRangeError, "Couldn't find an appropriate location to place extracted refactor"
384
+ end
380
385
 
381
386
  attribute_name = node.name[1..]
382
387
  indentation = " " * (closest_node.location.start_column + 2)
383
- attribute_accessor_source = T.must(
384
- case @code_action[:title]
385
- when CodeActions::CREATE_ATTRIBUTE_READER
386
- "#{indentation}attr_reader :#{attribute_name}\n\n"
387
- when CodeActions::CREATE_ATTRIBUTE_WRITER
388
- "#{indentation}attr_writer :#{attribute_name}\n\n"
389
- when CodeActions::CREATE_ATTRIBUTE_ACCESSOR
390
- "#{indentation}attr_accessor :#{attribute_name}\n\n"
391
- end,
392
- )
388
+ attribute_accessor_source = case @code_action[:title]
389
+ when CodeActions::CREATE_ATTRIBUTE_READER
390
+ "#{indentation}attr_reader :#{attribute_name}\n\n"
391
+ when CodeActions::CREATE_ATTRIBUTE_WRITER
392
+ "#{indentation}attr_writer :#{attribute_name}\n\n"
393
+ when CodeActions::CREATE_ATTRIBUTE_ACCESSOR
394
+ "#{indentation}attr_accessor :#{attribute_name}\n\n"
395
+ end #: as !nil
393
396
 
394
397
  target_start_line = closest_node.location.start_line
395
398
  target_range = {
@@ -20,20 +20,32 @@ module RubyLsp
20
20
 
21
21
  #: (GlobalState global_state, URI::Generic uri, Prism::Dispatcher dispatcher) -> void
22
22
  def initialize(global_state, uri, dispatcher)
23
- @response_builder = ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens]
23
+ @response_builder = ResponseBuilders::CollectionResponseBuilder
24
24
  .new #: ResponseBuilders::CollectionResponseBuilder[Interface::CodeLens]
25
25
  super()
26
- Listeners::CodeLens.new(@response_builder, global_state, uri, dispatcher)
26
+
27
+ @test_builder = ResponseBuilders::TestCollection.new #: ResponseBuilders::TestCollection
28
+
29
+ if global_state.enabled_feature?(:fullTestDiscovery)
30
+ Listeners::TestStyle.new(@test_builder, global_state, dispatcher, uri)
31
+ Listeners::SpecStyle.new(@test_builder, global_state, dispatcher, uri)
32
+ else
33
+ Listeners::CodeLens.new(@response_builder, global_state, uri, dispatcher)
34
+ end
27
35
 
28
36
  Addon.addons.each do |addon|
29
37
  addon.create_code_lens_listener(@response_builder, uri, dispatcher)
38
+
39
+ if global_state.enabled_feature?(:fullTestDiscovery)
40
+ addon.create_discover_tests_listener(@test_builder, dispatcher, uri)
41
+ end
30
42
  end
31
43
  end
32
44
 
33
45
  # @override
34
46
  #: -> Array[Interface::CodeLens]
35
47
  def perform
36
- @response_builder.response
48
+ @response_builder.response + @test_builder.code_lens
37
49
  end
38
50
  end
39
51
  end
@@ -21,7 +21,7 @@ module RubyLsp
21
21
  end
22
22
  end
23
23
 
24
- #: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] params, RubyDocument::SorbetLevel sorbet_level, Prism::Dispatcher dispatcher) -> void
24
+ #: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] params, SorbetLevel sorbet_level, Prism::Dispatcher dispatcher) -> void
25
25
  def initialize(document, global_state, params, sorbet_level, dispatcher)
26
26
  super()
27
27
  @target = nil #: Prism::Node?
@@ -60,7 +60,7 @@ module RubyLsp
60
60
  ],
61
61
  code_units_cache: document.code_units_cache,
62
62
  )
63
- @response_builder = ResponseBuilders::CollectionResponseBuilder[Interface::CompletionItem]
63
+ @response_builder = ResponseBuilders::CollectionResponseBuilder
64
64
  .new #: ResponseBuilders::CollectionResponseBuilder[Interface::CompletionItem]
65
65
 
66
66
  Listeners::Completion.new(
@@ -11,12 +11,11 @@ module RubyLsp
11
11
  class Definition < Request
12
12
  extend T::Generic
13
13
 
14
- #: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Prism::Dispatcher dispatcher, RubyDocument::SorbetLevel sorbet_level) -> void
14
+ #: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Prism::Dispatcher dispatcher, SorbetLevel sorbet_level) -> void
15
15
  def initialize(document, global_state, position, dispatcher, sorbet_level)
16
16
  super()
17
- @response_builder = ResponseBuilders::CollectionResponseBuilder[
18
- T.any(Interface::Location, Interface::LocationLink)
19
- ].new #: ResponseBuilders::CollectionResponseBuilder[(Interface::Location | Interface::LocationLink)]
17
+ @response_builder = ResponseBuilders::CollectionResponseBuilder
18
+ .new #: ResponseBuilders::CollectionResponseBuilder[(Interface::Location | Interface::LocationLink)]
20
19
  @dispatcher = dispatcher
21
20
 
22
21
  char_position, _ = document.find_index_by_position(position)
@@ -25,7 +25,7 @@ module RubyLsp
25
25
  code_units_cache: document.code_units_cache,
26
26
  )
27
27
 
28
- @response_builder = ResponseBuilders::CollectionResponseBuilder[Interface::DocumentHighlight]
28
+ @response_builder = ResponseBuilders::CollectionResponseBuilder
29
29
  .new #: ResponseBuilders::CollectionResponseBuilder[Interface::DocumentHighlight]
30
30
  Listeners::DocumentHighlight.new(
31
31
  @response_builder,
@@ -19,7 +19,7 @@ module RubyLsp
19
19
  #: (URI::Generic uri, Array[Prism::Comment] comments, Prism::Dispatcher dispatcher) -> void
20
20
  def initialize(uri, comments, dispatcher)
21
21
  super()
22
- @response_builder = ResponseBuilders::CollectionResponseBuilder[Interface::DocumentLink]
22
+ @response_builder = ResponseBuilders::CollectionResponseBuilder
23
23
  .new #: ResponseBuilders::CollectionResponseBuilder[Interface::DocumentLink]
24
24
  Listeners::DocumentLink.new(@response_builder, uri, comments, dispatcher)
25
25
  end
@@ -18,7 +18,7 @@ module RubyLsp
18
18
  #: (Array[Prism::Comment] comments, Prism::Dispatcher dispatcher) -> void
19
19
  def initialize(comments, dispatcher)
20
20
  super()
21
- @response_builder = ResponseBuilders::CollectionResponseBuilder[Interface::FoldingRange]
21
+ @response_builder = ResponseBuilders::CollectionResponseBuilder
22
22
  .new #: ResponseBuilders::CollectionResponseBuilder[Interface::FoldingRange]
23
23
  @listener = Listeners::FoldingRanges.new(@response_builder, comments, dispatcher) #: Listeners::FoldingRanges
24
24
  end
@@ -8,8 +8,6 @@ module RubyLsp
8
8
  # that navigates to the relevant file for the current document.
9
9
  # Currently, it supports source code file <> test file navigation.
10
10
  class GoToRelevantFile < Request
11
- extend T::Sig
12
-
13
11
  TEST_KEYWORDS = ["test", "spec", "integration_test"]
14
12
 
15
13
  TEST_PREFIX_PATTERN = /^(#{TEST_KEYWORDS.join("_|")}_)/
@@ -19,7 +19,7 @@ module RubyLsp
19
19
 
20
20
  ResponseType = type_member { { fixed: T.nilable(Interface::Hover) } }
21
21
 
22
- #: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Prism::Dispatcher dispatcher, RubyDocument::SorbetLevel sorbet_level) -> void
22
+ #: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Prism::Dispatcher dispatcher, SorbetLevel sorbet_level) -> void
23
23
  def initialize(document, global_state, position, dispatcher, sorbet_level)
24
24
  super()
25
25
 
@@ -20,7 +20,7 @@ module RubyLsp
20
20
  def initialize(document, hints_configuration, dispatcher)
21
21
  super()
22
22
 
23
- @response_builder = ResponseBuilders::CollectionResponseBuilder[Interface::InlayHint]
23
+ @response_builder = ResponseBuilders::CollectionResponseBuilder
24
24
  .new #: ResponseBuilders::CollectionResponseBuilder[Interface::InlayHint]
25
25
  Listeners::InlayHints.new(@response_builder, hints_configuration, dispatcher)
26
26
  end
@@ -55,22 +55,7 @@ module RubyLsp
55
55
  )
56
56
  end
57
57
 
58
- target = T.cast(
59
- target,
60
- T.any(
61
- Prism::ConstantReadNode,
62
- Prism::ConstantPathNode,
63
- Prism::ConstantPathTargetNode,
64
- Prism::InstanceVariableAndWriteNode,
65
- Prism::InstanceVariableOperatorWriteNode,
66
- Prism::InstanceVariableOrWriteNode,
67
- Prism::InstanceVariableReadNode,
68
- Prism::InstanceVariableTargetNode,
69
- Prism::InstanceVariableWriteNode,
70
- Prism::CallNode,
71
- Prism::DefNode,
72
- ),
73
- )
58
+ target = target #: as Prism::ConstantReadNode | Prism::ConstantPathNode | Prism::ConstantPathTargetNode | Prism::InstanceVariableAndWriteNode | Prism::InstanceVariableOperatorWriteNode | Prism::InstanceVariableOrWriteNode | Prism::InstanceVariableReadNode | Prism::InstanceVariableTargetNode | Prism::InstanceVariableWriteNode | Prism::CallNode | Prism::DefNode, # rubocop:disable Layout/LineLength
74
59
 
75
60
  reference_target = create_reference_target(target, node_context)
76
61
  return @locations unless reference_target
@@ -51,10 +51,7 @@ module RubyLsp
51
51
  )
52
52
  end
53
53
 
54
- target = T.cast(
55
- target,
56
- T.any(Prism::ConstantReadNode, Prism::ConstantPathNode, Prism::ConstantPathTargetNode),
57
- )
54
+ target = target #: as Prism::ConstantReadNode | Prism::ConstantPathNode | Prism::ConstantPathTargetNode
58
55
 
59
56
  name = RubyIndexer::Index.constant_name(target)
60
57
  return unless name
@@ -60,7 +60,8 @@ module RubyLsp
60
60
  return target unless parent.is_a?(Prism::ConstantPathNode)
61
61
 
62
62
  target = parent #: Prism::Node
63
- parent = T.cast(target, Prism::ConstantPathNode).parent #: Prism::Node?
63
+ parent = target #: as Prism::ConstantPathNode
64
+ .parent #: Prism::Node?
64
65
 
65
66
  while parent && cover?(parent.location, position)
66
67
  target = parent
@@ -32,7 +32,7 @@ module RubyLsp
32
32
  next unless node
33
33
 
34
34
  range = Support::SelectionRange.new(range: range_from_location(node.location), parent: parent)
35
- T.unsafe(queue).unshift(*node.child_nodes.map { |child| [child, range] })
35
+ queue.unshift(*node.child_nodes.map { |child| [child, range] })
36
36
  @ranges.unshift(range)
37
37
  end
38
38
 
@@ -74,7 +74,7 @@ module RubyLsp
74
74
  @result_id = 0 #: Integer
75
75
  @mutex = Mutex.new #: Mutex
76
76
 
77
- #: (GlobalState global_state, Prism::Dispatcher dispatcher, (RubyDocument | ERBDocument) document, String? previous_result_id, ?range: T::Range[Integer]?) -> void
77
+ #: (GlobalState global_state, Prism::Dispatcher dispatcher, (RubyDocument | ERBDocument) document, String? previous_result_id, ?range: Range[Integer]?) -> void
78
78
  def initialize(global_state, dispatcher, document, previous_result_id, range: nil)
79
79
  super()
80
80
 
@@ -46,7 +46,7 @@ module RubyLsp
46
46
  if (start_char..end_char).cover?(loc.start_offset..loc.end_offset)
47
47
  found_nodes << node
48
48
  else
49
- T.unsafe(queue).unshift(*node.child_nodes)
49
+ queue.unshift(*node.child_nodes)
50
50
  end
51
51
  end
52
52
 
@@ -19,7 +19,7 @@ module RubyLsp
19
19
  end
20
20
  end
21
21
 
22
- #: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Hash[Symbol, untyped]? context, Prism::Dispatcher dispatcher, RubyDocument::SorbetLevel sorbet_level) -> void
22
+ #: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Hash[Symbol, untyped]? context, Prism::Dispatcher dispatcher, SorbetLevel sorbet_level) -> void
23
23
  def initialize(document, global_state, position, context, dispatcher, sorbet_level) # rubocop:disable Metrics/ParameterLists
24
24
  super()
25
25
 
@@ -5,7 +5,7 @@ module RubyLsp
5
5
  module Requests
6
6
  module Support
7
7
  class Annotation
8
- #: (arity: (Integer | T::Range[Integer]), ?receiver: bool) -> void
8
+ #: (arity: (Integer | Range[Integer]), ?receiver: bool) -> void
9
9
  def initialize(arity:, receiver: false)
10
10
  @arity = arity
11
11
  @receiver = receiver
@@ -159,11 +159,6 @@ module RubyLsp
159
159
  Constant::SymbolKind::FIELD
160
160
  end
161
161
  end
162
-
163
- #: (RubyDocument::SorbetLevel sorbet_level) -> bool
164
- def sorbet_level_true_or_higher?(sorbet_level)
165
- sorbet_level == RubyDocument::SorbetLevel::True || sorbet_level == RubyDocument::SorbetLevel::Strict
166
- end
167
162
  end
168
163
  end
169
164
  end
@@ -21,8 +21,10 @@ module URI
21
21
  # have the uri gem in their own bundle and thus not use a compatible version.
22
22
  PARSER = const_defined?(:RFC2396_PARSER) ? RFC2396_PARSER : DEFAULT_PARSER #: RFC2396_Parser
23
23
 
24
- T.unsafe(self).alias_method(:gem_name, :host)
25
- T.unsafe(self).alias_method(:line_number, :fragment)
24
+ self #: as untyped # rubocop:disable Style/RedundantSelf
25
+ .alias_method(:gem_name, :host)
26
+ self #: as untyped # rubocop:disable Style/RedundantSelf
27
+ .alias_method(:line_number, :fragment)
26
28
 
27
29
  #: String?
28
30
  attr_reader :gem_version
@@ -13,6 +13,12 @@ module RubyLsp
13
13
  #: String
14
14
  attr_reader :id, :label
15
15
 
16
+ #: URI::Generic
17
+ attr_reader :uri
18
+
19
+ #: Interface::Range
20
+ attr_reader :range
21
+
16
22
  #: (String id, String label, URI::Generic uri, Interface::Range range, Symbol framework) -> void
17
23
  def initialize(id, label, uri, range, framework:)
18
24
  @id = id
@@ -32,7 +32,7 @@ module RubyLsp
32
32
  #: -> Interface::DocumentSymbol?
33
33
  def pop
34
34
  if @stack.size > 1
35
- T.cast(@stack.pop, Interface::DocumentSymbol)
35
+ @stack.pop #: as Interface::DocumentSymbol
36
36
  end
37
37
  end
38
38
 
@@ -8,10 +8,14 @@ module RubyLsp
8
8
 
9
9
  ResponseType = type_member { { fixed: Requests::Support::TestItem } }
10
10
 
11
+ #: Array[Interface::CodeLens]
12
+ attr_reader :code_lens
13
+
11
14
  #: -> void
12
15
  def initialize
13
16
  super
14
17
  @items = {} #: Hash[String, ResponseType]
18
+ @code_lens = [] #: Array[Interface::CodeLens]
15
19
  end
16
20
 
17
21
  #: (ResponseType item) -> void
@@ -19,6 +23,39 @@ module RubyLsp
19
23
  @items[item.id] = item
20
24
  end
21
25
 
26
+ #: (ResponseType item) -> void
27
+ def add_code_lens(item)
28
+ range = item.range
29
+ arguments = [item.uri.to_standardized_path, item.id]
30
+
31
+ @code_lens << Interface::CodeLens.new(
32
+ range: range,
33
+ command: Interface::Command.new(
34
+ title: "▶ Run",
35
+ command: "rubyLsp.runTest",
36
+ arguments: arguments,
37
+ ),
38
+ )
39
+
40
+ @code_lens << Interface::CodeLens.new(
41
+ range: range,
42
+ command: Interface::Command.new(
43
+ title: "▶ Run In Terminal",
44
+ command: "rubyLsp.runTestInTerminal",
45
+ arguments: arguments,
46
+ ),
47
+ )
48
+
49
+ @code_lens << Interface::CodeLens.new(
50
+ range: range,
51
+ command: Interface::Command.new(
52
+ title: "⚙ Debug",
53
+ command: "rubyLsp.debugTest",
54
+ arguments: arguments,
55
+ ),
56
+ )
57
+ end
58
+
22
59
  #: (String id) -> ResponseType?
23
60
  def [](id)
24
61
  @items[id]
@@ -23,16 +23,6 @@ module RubyLsp
23
23
  :private_class_method,
24
24
  ].freeze
25
25
 
26
- class SorbetLevel < T::Enum
27
- enums do
28
- None = new("none")
29
- Ignore = new("ignore")
30
- False = new("false")
31
- True = new("true")
32
- Strict = new("strict")
33
- end
34
- end
35
-
36
26
  class << self
37
27
  #: (Prism::Node node, Integer char_position, code_units_cache: (^(Integer arg0) -> Integer | Prism::CodeUnitsCache), ?node_types: Array[singleton(Prism::Node)]) -> NodeContext
38
28
  def locate(node, char_position, code_units_cache:, node_types: [])
@@ -53,7 +43,7 @@ module RubyLsp
53
43
  # Add the next child_nodes to the queue to be processed. The order here is important! We want to move in the
54
44
  # same order as the visiting mechanism, which means searching the child nodes before moving on to the next
55
45
  # sibling
56
- T.unsafe(queue).unshift(*candidate.child_nodes)
46
+ queue.unshift(*candidate.child_nodes)
57
47
 
58
48
  # Skip if the current node doesn't cover the desired position
59
49
  loc = candidate.location
@@ -154,29 +144,9 @@ module RubyLsp
154
144
  end
155
145
 
156
146
  # @override
157
- #: -> LanguageId
147
+ #: -> Symbol
158
148
  def language_id
159
- LanguageId::Ruby
160
- end
161
-
162
- #: -> SorbetLevel
163
- def sorbet_level
164
- sigil = parse_result.magic_comments.find do |comment|
165
- comment.key == "typed"
166
- end&.value
167
-
168
- case sigil
169
- when "ignore"
170
- SorbetLevel::Ignore
171
- when "false"
172
- SorbetLevel::False
173
- when "true"
174
- SorbetLevel::True
175
- when "strict", "strong"
176
- SorbetLevel::Strict
177
- else
178
- SorbetLevel::None
179
- end
149
+ :ruby
180
150
  end
181
151
 
182
152
  #: (Hash[Symbol, untyped] range, ?node_types: Array[singleton(Prism::Node)]) -> Prism::Node?
@@ -195,7 +165,7 @@ module RubyLsp
195
165
  # Add the next child_nodes to the queue to be processed. The order here is important! We want to move in the
196
166
  # same order as the visiting mechanism, which means searching the child nodes before moving on to the next
197
167
  # sibling
198
- T.unsafe(queue).unshift(*candidate.child_nodes)
168
+ queue.unshift(*candidate.child_nodes)
199
169
 
200
170
  # Skip if the current node doesn't cover the desired position
201
171
  loc = candidate.location