ruby-lsp 0.23.11 → 0.23.12

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 (98) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/VERSION +1 -1
  4. data/exe/ruby-lsp-launcher +12 -11
  5. data/lib/rubocop/cop/ruby_lsp/use_register_with_handler_method.rb +3 -5
  6. data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +52 -77
  7. data/lib/ruby_indexer/lib/ruby_indexer/declaration_listener.rb +61 -144
  8. data/lib/ruby_indexer/lib/ruby_indexer/enhancement.rb +8 -6
  9. data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +73 -182
  10. data/lib/ruby_indexer/lib/ruby_indexer/index.rb +48 -181
  11. data/lib/ruby_indexer/lib/ruby_indexer/location.rb +4 -27
  12. data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +12 -14
  13. data/lib/ruby_indexer/lib/ruby_indexer/rbs_indexer.rb +21 -44
  14. data/lib/ruby_indexer/lib/ruby_indexer/reference_finder.rb +40 -58
  15. data/lib/ruby_indexer/lib/ruby_indexer/uri.rb +9 -16
  16. data/lib/ruby_indexer/lib/ruby_indexer/visibility_scope.rb +5 -9
  17. data/lib/ruby_indexer/test/configuration_test.rb +32 -2
  18. data/lib/ruby_indexer/test/method_test.rb +2 -2
  19. data/lib/ruby_lsp/addon.rb +32 -67
  20. data/lib/ruby_lsp/base_server.rb +10 -10
  21. data/lib/ruby_lsp/client_capabilities.rb +4 -6
  22. data/lib/ruby_lsp/document.rb +21 -32
  23. data/lib/ruby_lsp/erb_document.rb +17 -27
  24. data/lib/ruby_lsp/global_state.rb +30 -32
  25. data/lib/ruby_lsp/internal.rb +2 -0
  26. data/lib/ruby_lsp/listeners/code_lens.rb +21 -39
  27. data/lib/ruby_lsp/listeners/completion.rb +34 -53
  28. data/lib/ruby_lsp/listeners/definition.rb +35 -49
  29. data/lib/ruby_lsp/listeners/document_highlight.rb +60 -69
  30. data/lib/ruby_lsp/listeners/document_link.rb +9 -19
  31. data/lib/ruby_lsp/listeners/document_symbol.rb +34 -48
  32. data/lib/ruby_lsp/listeners/folding_ranges.rb +31 -38
  33. data/lib/ruby_lsp/listeners/hover.rb +37 -47
  34. data/lib/ruby_lsp/listeners/inlay_hints.rb +3 -10
  35. data/lib/ruby_lsp/listeners/semantic_highlighting.rb +29 -35
  36. data/lib/ruby_lsp/listeners/signature_help.rb +4 -23
  37. data/lib/ruby_lsp/listeners/spec_style.rb +199 -0
  38. data/lib/ruby_lsp/listeners/test_style.rb +136 -30
  39. data/lib/ruby_lsp/node_context.rb +8 -35
  40. data/lib/ruby_lsp/rbs_document.rb +7 -5
  41. data/lib/ruby_lsp/requests/code_action_resolve.rb +10 -10
  42. data/lib/ruby_lsp/requests/code_actions.rb +5 -14
  43. data/lib/ruby_lsp/requests/code_lens.rb +4 -13
  44. data/lib/ruby_lsp/requests/completion.rb +4 -15
  45. data/lib/ruby_lsp/requests/completion_resolve.rb +4 -4
  46. data/lib/ruby_lsp/requests/definition.rb +4 -12
  47. data/lib/ruby_lsp/requests/diagnostics.rb +6 -9
  48. data/lib/ruby_lsp/requests/discover_tests.rb +15 -3
  49. data/lib/ruby_lsp/requests/document_highlight.rb +3 -11
  50. data/lib/ruby_lsp/requests/document_link.rb +4 -13
  51. data/lib/ruby_lsp/requests/document_symbol.rb +4 -7
  52. data/lib/ruby_lsp/requests/folding_ranges.rb +4 -7
  53. data/lib/ruby_lsp/requests/formatting.rb +4 -7
  54. data/lib/ruby_lsp/requests/go_to_relevant_file.rb +87 -0
  55. data/lib/ruby_lsp/requests/hover.rb +6 -16
  56. data/lib/ruby_lsp/requests/inlay_hints.rb +4 -13
  57. data/lib/ruby_lsp/requests/on_type_formatting.rb +17 -24
  58. data/lib/ruby_lsp/requests/prepare_rename.rb +3 -8
  59. data/lib/ruby_lsp/requests/prepare_type_hierarchy.rb +4 -13
  60. data/lib/ruby_lsp/requests/range_formatting.rb +3 -4
  61. data/lib/ruby_lsp/requests/references.rb +5 -35
  62. data/lib/ruby_lsp/requests/rename.rb +9 -35
  63. data/lib/ruby_lsp/requests/request.rb +5 -17
  64. data/lib/ruby_lsp/requests/selection_ranges.rb +3 -3
  65. data/lib/ruby_lsp/requests/semantic_highlighting.rb +6 -23
  66. data/lib/ruby_lsp/requests/show_syntax_tree.rb +4 -5
  67. data/lib/ruby_lsp/requests/signature_help.rb +6 -24
  68. data/lib/ruby_lsp/requests/support/annotation.rb +4 -10
  69. data/lib/ruby_lsp/requests/support/common.rb +12 -49
  70. data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +12 -14
  71. data/lib/ruby_lsp/requests/support/rubocop_formatter.rb +7 -10
  72. data/lib/ruby_lsp/requests/support/rubocop_runner.rb +9 -15
  73. data/lib/ruby_lsp/requests/support/selection_range.rb +1 -3
  74. data/lib/ruby_lsp/requests/support/sorbet.rb +1 -7
  75. data/lib/ruby_lsp/requests/support/source_uri.rb +5 -16
  76. data/lib/ruby_lsp/requests/support/syntax_tree_formatter.rb +7 -10
  77. data/lib/ruby_lsp/requests/support/test_item.rb +14 -13
  78. data/lib/ruby_lsp/requests/type_hierarchy_supertypes.rb +4 -5
  79. data/lib/ruby_lsp/requests/workspace_symbol.rb +3 -3
  80. data/lib/ruby_lsp/response_builders/collection_response_builder.rb +4 -4
  81. data/lib/ruby_lsp/response_builders/document_symbol.rb +8 -11
  82. data/lib/ruby_lsp/response_builders/hover.rb +5 -5
  83. data/lib/ruby_lsp/response_builders/response_builder.rb +1 -1
  84. data/lib/ruby_lsp/response_builders/semantic_highlighting.rb +18 -40
  85. data/lib/ruby_lsp/response_builders/signature_help.rb +4 -5
  86. data/lib/ruby_lsp/response_builders/test_collection.rb +5 -9
  87. data/lib/ruby_lsp/ruby_document.rb +15 -40
  88. data/lib/ruby_lsp/ruby_lsp_reporter_plugin.rb +106 -0
  89. data/lib/ruby_lsp/scope.rb +6 -10
  90. data/lib/ruby_lsp/server.rb +125 -74
  91. data/lib/ruby_lsp/setup_bundler.rb +22 -15
  92. data/lib/ruby_lsp/store.rb +12 -28
  93. data/lib/ruby_lsp/test_helper.rb +3 -12
  94. data/lib/ruby_lsp/test_reporter.rb +71 -0
  95. data/lib/ruby_lsp/test_unit_test_runner.rb +96 -0
  96. data/lib/ruby_lsp/type_inferrer.rb +9 -13
  97. data/lib/ruby_lsp/utils.rb +27 -65
  98. metadata +8 -3
@@ -6,12 +6,8 @@ module RubyLsp
6
6
  # The [on type formatting](https://microsoft.github.io/language-server-protocol/specification#textDocument_onTypeFormatting)
7
7
  # request formats code as the user is typing. For example, automatically adding `end` to class definitions.
8
8
  class OnTypeFormatting < Request
9
- extend T::Sig
10
-
11
9
  class << self
12
- extend T::Sig
13
-
14
- sig { returns(Interface::DocumentOnTypeFormattingRegistrationOptions) }
10
+ #: -> Interface::DocumentOnTypeFormattingRegistrationOptions
15
11
  def provider
16
12
  Interface::DocumentOnTypeFormattingRegistrationOptions.new(
17
13
  document_selector: nil,
@@ -30,14 +26,7 @@ module RubyLsp
30
26
  T::Array[Regexp],
31
27
  )
32
28
 
33
- sig do
34
- params(
35
- document: RubyDocument,
36
- position: T::Hash[Symbol, T.untyped],
37
- trigger_character: String,
38
- client_name: String,
39
- ).void
40
- end
29
+ #: (RubyDocument document, Hash[Symbol, untyped] position, String trigger_character, String client_name) -> void
41
30
  def initialize(document, position, trigger_character, client_name)
42
31
  super()
43
32
  @document = document
@@ -52,7 +41,8 @@ module RubyLsp
52
41
  @client_name = client_name
53
42
  end
54
43
 
55
- sig { override.returns(T.all(T::Array[Interface::TextEdit], Object)) }
44
+ # @override
45
+ #: -> (Array[Interface::TextEdit] & Object)
56
46
  def perform
57
47
  case @trigger_character
58
48
  when "{"
@@ -60,7 +50,10 @@ module RubyLsp
60
50
  when "|"
61
51
  handle_pipe if @document.syntax_error?
62
52
  when "\n"
63
- if (comment_match = @previous_line.match(/^#(\s*)/))
53
+ # If the previous line is a simple comment, we'll add a comment continuation
54
+ # But if it's a RBS signature starting with `#:`, we'll ignore it
55
+ # so users can immediately continue typing the method definition
56
+ if (comment_match = @previous_line.match(/^#(?!:)(\s*)/))
64
57
  handle_comment_line(T.must(comment_match[1]))
65
58
  elsif @document.syntax_error?
66
59
  match = /(<<((-|~)?))(?<quote>['"`]?)(?<delimiter>\w+)\k<quote>/.match(@previous_line)
@@ -81,7 +74,7 @@ module RubyLsp
81
74
 
82
75
  private
83
76
 
84
- sig { void }
77
+ #: -> void
85
78
  def handle_pipe
86
79
  current_line = @lines[@position[:line]]
87
80
  return unless /((?<=do)|(?<={))\s+\|/.match?(current_line)
@@ -112,7 +105,7 @@ module RubyLsp
112
105
  move_cursor_to(@position[:line], @position[:character])
113
106
  end
114
107
 
115
- sig { void }
108
+ #: -> void
116
109
  def handle_curly_brace
117
110
  return unless /".*#\{/.match?(@previous_line)
118
111
 
@@ -120,7 +113,7 @@ module RubyLsp
120
113
  move_cursor_to(@position[:line], @position[:character])
121
114
  end
122
115
 
123
- sig { void }
116
+ #: -> void
124
117
  def handle_statement_end
125
118
  # If a keyword occurs in a line which appears be a comment or a string, we will not try to format it, since
126
119
  # it could be a coincidental match. This approach is not perfect, but it should cover most cases.
@@ -142,7 +135,7 @@ module RubyLsp
142
135
  end
143
136
  end
144
137
 
145
- sig { params(delimiter: String).void }
138
+ #: (String delimiter) -> void
146
139
  def handle_heredoc_end(delimiter)
147
140
  indents = " " * @indentation
148
141
  add_edit_with_text("\n")
@@ -150,12 +143,12 @@ module RubyLsp
150
143
  move_cursor_to(@position[:line], @indentation + 2)
151
144
  end
152
145
 
153
- sig { params(spaces: String).void }
146
+ #: (String spaces) -> void
154
147
  def handle_comment_line(spaces)
155
148
  add_edit_with_text("##{spaces}")
156
149
  end
157
150
 
158
- sig { params(text: String, position: T::Hash[Symbol, T.untyped]).void }
151
+ #: (String text, ?Hash[Symbol, untyped] position) -> void
159
152
  def add_edit_with_text(text, position = @position)
160
153
  pos = Interface::Position.new(
161
154
  line: position[:line],
@@ -168,7 +161,7 @@ module RubyLsp
168
161
  )
169
162
  end
170
163
 
171
- sig { params(line: Integer, character: Integer).void }
164
+ #: (Integer line, Integer character) -> void
172
165
  def move_cursor_to(line, character)
173
166
  return unless /Visual Studio Code|Cursor/.match?(@client_name)
174
167
 
@@ -189,7 +182,7 @@ module RubyLsp
189
182
  )
190
183
  end
191
184
 
192
- sig { params(line: String).returns(Integer) }
185
+ #: (String line) -> Integer
193
186
  def find_indentation(line)
194
187
  count = 0
195
188
 
@@ -202,7 +195,7 @@ module RubyLsp
202
195
  count
203
196
  end
204
197
 
205
- sig { void }
198
+ #: -> void
206
199
  def auto_indent_after_end_keyword
207
200
  current_line = @lines[@position[:line]]
208
201
  return unless current_line && current_line.strip == "end"
@@ -7,22 +7,17 @@ module RubyLsp
7
7
  # [prepare_rename](https://microsoft.github.io/language-server-protocol/specification#textDocument_prepareRename)
8
8
  # # request checks the validity of a rename operation at a given location.
9
9
  class PrepareRename < Request
10
- extend T::Sig
11
10
  include Support::Common
12
11
 
13
- sig do
14
- params(
15
- document: RubyDocument,
16
- position: T::Hash[Symbol, T.untyped],
17
- ).void
18
- end
12
+ #: (RubyDocument document, Hash[Symbol, untyped] position) -> void
19
13
  def initialize(document, position)
20
14
  super()
21
15
  @document = document
22
16
  @position = T.let(position, T::Hash[Symbol, Integer])
23
17
  end
24
18
 
25
- sig { override.returns(T.nilable(Interface::Range)) }
19
+ # @override
20
+ #: -> Interface::Range?
26
21
  def perform
27
22
  char_position, _ = @document.find_index_by_position(@position)
28
23
 
@@ -9,26 +9,16 @@ module RubyLsp
9
9
  #
10
10
  # Currently only supports supertypes due to a limitation of the index.
11
11
  class PrepareTypeHierarchy < Request
12
- extend T::Sig
13
-
14
12
  include Support::Common
15
13
 
16
14
  class << self
17
- extend T::Sig
18
-
19
- sig { returns(Interface::TypeHierarchyOptions) }
15
+ #: -> Interface::TypeHierarchyOptions
20
16
  def provider
21
17
  Interface::TypeHierarchyOptions.new
22
18
  end
23
19
  end
24
20
 
25
- sig do
26
- params(
27
- document: T.any(RubyDocument, ERBDocument),
28
- index: RubyIndexer::Index,
29
- position: T::Hash[Symbol, T.untyped],
30
- ).void
31
- end
21
+ #: ((RubyDocument | ERBDocument) document, RubyIndexer::Index index, Hash[Symbol, untyped] position) -> void
32
22
  def initialize(document, index, position)
33
23
  super()
34
24
 
@@ -37,7 +27,8 @@ module RubyLsp
37
27
  @position = position
38
28
  end
39
29
 
40
- sig { override.returns(T.nilable(T::Array[Interface::TypeHierarchyItem])) }
30
+ # @override
31
+ #: -> Array[Interface::TypeHierarchyItem]?
41
32
  def perform
42
33
  context = @document.locate_node(
43
34
  @position,
@@ -6,9 +6,7 @@ module RubyLsp
6
6
  # The [range formatting](https://microsoft.github.io/language-server-protocol/specification#textDocument_rangeFormatting)
7
7
  # is used to format a selection or to format on paste.
8
8
  class RangeFormatting < Request
9
- extend T::Sig
10
-
11
- sig { params(global_state: GlobalState, document: RubyDocument, params: T::Hash[Symbol, T.untyped]).void }
9
+ #: (GlobalState global_state, RubyDocument document, Hash[Symbol, untyped] params) -> void
12
10
  def initialize(global_state, document, params)
13
11
  super()
14
12
  @document = document
@@ -17,7 +15,8 @@ module RubyLsp
17
15
  @active_formatter = T.let(global_state.active_formatter, T.nilable(Support::Formatter))
18
16
  end
19
17
 
20
- sig { override.returns(T.nilable(T::Array[Interface::TextEdit])) }
18
+ # @override
19
+ #: -> Array[Interface::TextEdit]?
21
20
  def perform
22
21
  return unless @active_formatter
23
22
  return if @document.syntax_error?
@@ -7,17 +7,9 @@ module RubyLsp
7
7
  # [references](https://microsoft.github.io/language-server-protocol/specification#textDocument_references)
8
8
  # request finds all references for the selected symbol.
9
9
  class References < Request
10
- extend T::Sig
11
10
  include Support::Common
12
11
 
13
- sig do
14
- params(
15
- global_state: GlobalState,
16
- store: Store,
17
- document: T.any(RubyDocument, ERBDocument),
18
- params: T::Hash[Symbol, T.untyped],
19
- ).void
20
- end
12
+ #: (GlobalState global_state, Store store, (RubyDocument | ERBDocument) document, Hash[Symbol, untyped] params) -> void
21
13
  def initialize(global_state, store, document, params)
22
14
  super()
23
15
  @global_state = global_state
@@ -27,7 +19,8 @@ module RubyLsp
27
19
  @locations = T.let([], T::Array[Interface::Location])
28
20
  end
29
21
 
30
- sig { override.returns(T::Array[Interface::Location]) }
22
+ # @override
23
+ #: -> Array[Interface::Location]
31
24
  def perform
32
25
  position = @params[:position]
33
26
  char_position, _ = @document.find_index_by_position(position)
@@ -103,24 +96,7 @@ module RubyLsp
103
96
 
104
97
  private
105
98
 
106
- sig do
107
- params(
108
- target_node: T.any(
109
- Prism::ConstantReadNode,
110
- Prism::ConstantPathNode,
111
- Prism::ConstantPathTargetNode,
112
- Prism::InstanceVariableAndWriteNode,
113
- Prism::InstanceVariableOperatorWriteNode,
114
- Prism::InstanceVariableOrWriteNode,
115
- Prism::InstanceVariableReadNode,
116
- Prism::InstanceVariableTargetNode,
117
- Prism::InstanceVariableWriteNode,
118
- Prism::CallNode,
119
- Prism::DefNode,
120
- ),
121
- node_context: NodeContext,
122
- ).returns(T.nilable(RubyIndexer::ReferenceFinder::Target))
123
- end
99
+ #: ((Prism::ConstantReadNode | Prism::ConstantPathNode | Prism::ConstantPathTargetNode | Prism::InstanceVariableAndWriteNode | Prism::InstanceVariableOperatorWriteNode | Prism::InstanceVariableOrWriteNode | Prism::InstanceVariableReadNode | Prism::InstanceVariableTargetNode | Prism::InstanceVariableWriteNode | Prism::CallNode | Prism::DefNode) target_node, NodeContext node_context) -> RubyIndexer::ReferenceFinder::Target?
124
100
  def create_reference_target(target_node, node_context)
125
101
  case target_node
126
102
  when Prism::ConstantReadNode, Prism::ConstantPathNode, Prism::ConstantPathTargetNode
@@ -145,13 +121,7 @@ module RubyLsp
145
121
  end
146
122
  end
147
123
 
148
- sig do
149
- params(
150
- target: RubyIndexer::ReferenceFinder::Target,
151
- parse_result: Prism::ParseResult,
152
- uri: URI::Generic,
153
- ).void
154
- end
124
+ #: (RubyIndexer::ReferenceFinder::Target target, Prism::ParseResult parse_result, URI::Generic uri) -> void
155
125
  def collect_references(target, parse_result, uri)
156
126
  dispatcher = Prism::Dispatcher.new
157
127
  finder = RubyIndexer::ReferenceFinder.new(
@@ -7,28 +7,18 @@ module RubyLsp
7
7
  # [rename](https://microsoft.github.io/language-server-protocol/specification#textDocument_rename)
8
8
  # request renames all instances of a symbol in a document.
9
9
  class Rename < Request
10
- extend T::Sig
11
10
  include Support::Common
12
11
 
13
12
  class InvalidNameError < StandardError; end
14
13
 
15
14
  class << self
16
- extend T::Sig
17
-
18
- sig { returns(Interface::RenameOptions) }
15
+ #: -> Interface::RenameOptions
19
16
  def provider
20
17
  Interface::RenameOptions.new(prepare_provider: true)
21
18
  end
22
19
  end
23
20
 
24
- sig do
25
- params(
26
- global_state: GlobalState,
27
- store: Store,
28
- document: T.any(RubyDocument, ERBDocument),
29
- params: T::Hash[Symbol, T.untyped],
30
- ).void
31
- end
21
+ #: (GlobalState global_state, Store store, (RubyDocument | ERBDocument) document, Hash[Symbol, untyped] params) -> void
32
22
  def initialize(global_state, store, document, params)
33
23
  super()
34
24
  @global_state = global_state
@@ -38,7 +28,8 @@ module RubyLsp
38
28
  @new_name = T.let(params[:newName], String)
39
29
  end
40
30
 
41
- sig { override.returns(T.nilable(Interface::WorkspaceEdit)) }
31
+ # @override
32
+ #: -> Interface::WorkspaceEdit?
42
33
  def perform
43
34
  char_position, _ = @document.find_index_by_position(@position)
44
35
 
@@ -100,12 +91,7 @@ module RubyLsp
100
91
 
101
92
  private
102
93
 
103
- sig do
104
- params(
105
- fully_qualified_name: String,
106
- document_changes: T::Array[T.any(Interface::RenameFile, Interface::TextDocumentEdit)],
107
- ).void
108
- end
94
+ #: (String fully_qualified_name, Array[(Interface::RenameFile | Interface::TextDocumentEdit)] document_changes) -> void
109
95
  def collect_file_renames(fully_qualified_name, document_changes)
110
96
  # Check if the declarations of the symbol being renamed match the file name. In case they do, we automatically
111
97
  # rename the files for the user.
@@ -139,12 +125,7 @@ module RubyLsp
139
125
  end
140
126
  end
141
127
 
142
- sig do
143
- params(
144
- target: RubyIndexer::ReferenceFinder::Target,
145
- name: String,
146
- ).returns(T::Hash[String, T::Array[Interface::TextEdit]])
147
- end
128
+ #: (RubyIndexer::ReferenceFinder::Target target, String name) -> Hash[String, Array[Interface::TextEdit]]
148
129
  def collect_text_edits(target, name)
149
130
  changes = {}
150
131
 
@@ -169,14 +150,7 @@ module RubyLsp
169
150
  changes
170
151
  end
171
152
 
172
- sig do
173
- params(
174
- target: RubyIndexer::ReferenceFinder::Target,
175
- parse_result: Prism::ParseResult,
176
- name: String,
177
- uri: URI::Generic,
178
- ).returns(T::Array[Interface::TextEdit])
179
- end
153
+ #: (RubyIndexer::ReferenceFinder::Target target, Prism::ParseResult parse_result, String name, URI::Generic uri) -> Array[Interface::TextEdit]
180
154
  def collect_changes(target, parse_result, name, uri)
181
155
  dispatcher = Prism::Dispatcher.new
182
156
  finder = RubyIndexer::ReferenceFinder.new(target, @global_state.index, dispatcher, uri)
@@ -187,7 +161,7 @@ module RubyLsp
187
161
  end
188
162
  end
189
163
 
190
- sig { params(name: String, reference: RubyIndexer::ReferenceFinder::Reference).returns(Interface::TextEdit) }
164
+ #: (String name, RubyIndexer::ReferenceFinder::Reference reference) -> Interface::TextEdit
191
165
  def adjust_reference_for_edit(name, reference)
192
166
  # The reference may include a namespace in front. We need to check if the rename new name includes namespaces
193
167
  # and then adjust both the text and the location to produce the correct edit
@@ -197,7 +171,7 @@ module RubyLsp
197
171
  Interface::TextEdit.new(range: range_from_location(location), new_text: new_text)
198
172
  end
199
173
 
200
- sig { params(constant_name: String).returns(String) }
174
+ #: (String constant_name) -> String
201
175
  def file_from_constant_name(constant_name)
202
176
  constant_name
203
177
  .gsub(/([a-z])([A-Z])|([A-Z])([A-Z][a-z])/, '\1\3_\2\4')
@@ -4,8 +4,8 @@
4
4
  module RubyLsp
5
5
  module Requests
6
6
  class Request
7
- extend T::Sig
8
7
  extend T::Generic
8
+ extend T::Sig
9
9
 
10
10
  class InvalidFormatter < StandardError; end
11
11
 
@@ -18,13 +18,7 @@ module RubyLsp
18
18
 
19
19
  # Signals to the client that the request should be delegated to the language server server for the host language
20
20
  # in ERB files
21
- sig do
22
- params(
23
- global_state: GlobalState,
24
- document: Document[T.untyped],
25
- char_position: Integer,
26
- ).void
27
- end
21
+ #: (GlobalState global_state, Document[untyped] document, Integer char_position) -> void
28
22
  def delegate_request_if_needed!(global_state, document, char_position)
29
23
  if global_state.client_capabilities.supports_request_delegation &&
30
24
  document.is_a?(ERBDocument) &&
@@ -34,7 +28,7 @@ module RubyLsp
34
28
  end
35
29
 
36
30
  # Checks if a location covers a position
37
- sig { params(location: Prism::Location, position: T.untyped).returns(T::Boolean) }
31
+ #: (Prism::Location location, untyped position) -> bool
38
32
  def cover?(location, position)
39
33
  start_covered =
40
34
  location.start_line - 1 < position[:line] ||
@@ -61,13 +55,7 @@ module RubyLsp
61
55
  # # ^ Going to definition here should go to Foo::Bar
62
56
  # #^ Going to definition here should go to Foo
63
57
  # ```
64
- sig do
65
- params(
66
- target: Prism::Node,
67
- parent: Prism::Node,
68
- position: T::Hash[Symbol, Integer],
69
- ).returns(Prism::Node)
70
- end
58
+ #: (Prism::Node target, Prism::Node parent, Hash[Symbol, Integer] position) -> Prism::Node
71
59
  def determine_target(target, parent, position)
72
60
  return target unless parent.is_a?(Prism::ConstantPathNode)
73
61
 
@@ -83,7 +71,7 @@ module RubyLsp
83
71
  end
84
72
 
85
73
  # Checks if a given location covers the position requested
86
- sig { params(location: T.nilable(Prism::Location), position: T::Hash[Symbol, T.untyped]).returns(T::Boolean) }
74
+ #: (Prism::Location? location, Hash[Symbol, untyped] position) -> bool
87
75
  def covers_position?(location, position)
88
76
  return false unless location
89
77
 
@@ -11,10 +11,9 @@ module RubyLsp
11
11
  #
12
12
  # Note that if using VSCode Neovim, you will need to be in Insert mode for this to work correctly.
13
13
  class SelectionRanges < Request
14
- extend T::Sig
15
14
  include Support::Common
16
15
 
17
- sig { params(document: T.any(RubyDocument, ERBDocument)).void }
16
+ #: ((RubyDocument | ERBDocument) document) -> void
18
17
  def initialize(document)
19
18
  super()
20
19
  @document = document
@@ -22,7 +21,8 @@ module RubyLsp
22
21
  @stack = T.let([], T::Array[Support::SelectionRange])
23
22
  end
24
23
 
25
- sig { override.returns(T.all(T::Array[Support::SelectionRange], Object)) }
24
+ # @override
25
+ #: -> (Array[Support::SelectionRange] & Object)
26
26
  def perform
27
27
  # [node, parent]
28
28
  queue = [[@document.parse_result.value, nil]]
@@ -9,12 +9,8 @@ module RubyLsp
9
9
  # highlighting](https://microsoft.github.io/language-server-protocol/specification#textDocument_semanticTokens)
10
10
  # request informs the editor of the correct token types to provide consistent and accurate highlighting for themes.
11
11
  class SemanticHighlighting < Request
12
- extend T::Sig
13
-
14
12
  class << self
15
- extend T::Sig
16
-
17
- sig { returns(Interface::SemanticTokensRegistrationOptions) }
13
+ #: -> Interface::SemanticTokensRegistrationOptions
18
14
  def provider
19
15
  Interface::SemanticTokensRegistrationOptions.new(
20
16
  document_selector: nil,
@@ -29,13 +25,7 @@ module RubyLsp
29
25
 
30
26
  # The compute_delta method receives the current semantic tokens and the previous semantic tokens and then tries
31
27
  # to compute the smallest possible semantic token edit that will turn previous into current
32
- sig do
33
- params(
34
- current_tokens: T::Array[Integer],
35
- previous_tokens: T::Array[Integer],
36
- result_id: String,
37
- ).returns(Interface::SemanticTokensDelta)
38
- end
28
+ #: (Array[Integer] current_tokens, Array[Integer] previous_tokens, String result_id) -> Interface::SemanticTokensDelta
39
29
  def compute_delta(current_tokens, previous_tokens, result_id)
40
30
  # Find the index of the first token that is different between the two sets of tokens
41
31
  first_different_position = current_tokens.zip(previous_tokens).find_index { |new, old| new != old }
@@ -73,7 +63,7 @@ module RubyLsp
73
63
  )
74
64
  end
75
65
 
76
- sig { returns(Integer) }
66
+ #: -> Integer
77
67
  def next_result_id
78
68
  @mutex.synchronize do
79
69
  @result_id += 1
@@ -84,15 +74,7 @@ module RubyLsp
84
74
  @result_id = T.let(0, Integer)
85
75
  @mutex = T.let(Mutex.new, Mutex)
86
76
 
87
- sig do
88
- params(
89
- global_state: GlobalState,
90
- dispatcher: Prism::Dispatcher,
91
- document: T.any(RubyDocument, ERBDocument),
92
- previous_result_id: T.nilable(String),
93
- range: T.nilable(T::Range[Integer]),
94
- ).void
95
- end
77
+ #: (GlobalState global_state, Prism::Dispatcher dispatcher, (RubyDocument | ERBDocument) document, String? previous_result_id, ?range: T::Range[Integer]?) -> void
96
78
  def initialize(global_state, dispatcher, document, previous_result_id, range: nil)
97
79
  super()
98
80
 
@@ -111,7 +93,8 @@ module RubyLsp
111
93
  end
112
94
  end
113
95
 
114
- sig { override.returns(T.any(Interface::SemanticTokens, Interface::SemanticTokensDelta)) }
96
+ # @override
97
+ #: -> (Interface::SemanticTokens | Interface::SemanticTokensDelta)
115
98
  def perform
116
99
  previous_tokens = @document.semantic_tokens
117
100
  tokens = @response_builder.response
@@ -7,9 +7,7 @@ module RubyLsp
7
7
  # request](https://microsoft.github.io/language-server-protocol/specification#requestMessage) that displays the AST
8
8
  # for the current document or for the current selection in a new tab.
9
9
  class ShowSyntaxTree < Request
10
- extend T::Sig
11
-
12
- sig { params(document: RubyDocument, range: T.nilable(T::Hash[Symbol, T.untyped])).void }
10
+ #: (RubyDocument document, Hash[Symbol, untyped]? range) -> void
13
11
  def initialize(document, range)
14
12
  super()
15
13
  @document = document
@@ -17,7 +15,8 @@ module RubyLsp
17
15
  @tree = T.let(document.parse_result.value, Prism::ProgramNode)
18
16
  end
19
17
 
20
- sig { override.returns(String) }
18
+ # @override
19
+ #: -> String
21
20
  def perform
22
21
  return ast_for_range if @range
23
22
 
@@ -28,7 +27,7 @@ module RubyLsp
28
27
 
29
28
  private
30
29
 
31
- sig { returns(String) }
30
+ #: -> String
32
31
  def ast_for_range
33
32
  range = T.must(@range)
34
33
  start_char, end_char = @document.find_index_by_position(range[:start], range[:end])
@@ -9,12 +9,8 @@ module RubyLsp
9
9
  # request](https://microsoft.github.io/language-server-protocol/specification#textDocument_signatureHelp) displays
10
10
  # information about the parameters of a method as you type an invocation.
11
11
  class SignatureHelp < Request
12
- extend T::Sig
13
-
14
12
  class << self
15
- extend T::Sig
16
-
17
- sig { returns(Interface::SignatureHelpOptions) }
13
+ #: -> Interface::SignatureHelpOptions
18
14
  def provider
19
15
  # Identifier characters are automatically included, such as A-Z, a-z, 0-9, _, * or :
20
16
  Interface::SignatureHelpOptions.new(
@@ -23,16 +19,7 @@ module RubyLsp
23
19
  end
24
20
  end
25
21
 
26
- sig do
27
- params(
28
- document: T.any(RubyDocument, ERBDocument),
29
- global_state: GlobalState,
30
- position: T::Hash[Symbol, T.untyped],
31
- context: T.nilable(T::Hash[Symbol, T.untyped]),
32
- dispatcher: Prism::Dispatcher,
33
- sorbet_level: RubyDocument::SorbetLevel,
34
- ).void
35
- end
22
+ #: ((RubyDocument | ERBDocument) document, GlobalState global_state, Hash[Symbol, untyped] position, Hash[Symbol, untyped]? context, Prism::Dispatcher dispatcher, RubyDocument::SorbetLevel sorbet_level) -> void
36
23
  def initialize(document, global_state, position, context, dispatcher, sorbet_level) # rubocop:disable Metrics/ParameterLists
37
24
  super()
38
25
 
@@ -54,7 +41,8 @@ module RubyLsp
54
41
  Listeners::SignatureHelp.new(@response_builder, global_state, node_context, dispatcher, sorbet_level)
55
42
  end
56
43
 
57
- sig { override.returns(T.nilable(Interface::SignatureHelp)) }
44
+ # @override
45
+ #: -> Interface::SignatureHelp?
58
46
  def perform
59
47
  return unless @target
60
48
 
@@ -70,13 +58,7 @@ module RubyLsp
70
58
  # foo(another_method_call)
71
59
  #
72
60
  # In that case, we want to provide signature help for `foo` and not `another_method_call`.
73
- sig do
74
- params(
75
- target: T.nilable(Prism::Node),
76
- parent: T.nilable(Prism::Node),
77
- position: T::Hash[Symbol, T.untyped],
78
- ).returns(T.nilable(Prism::Node))
79
- end
61
+ #: (Prism::Node? target, Prism::Node? parent, Hash[Symbol, untyped] position) -> Prism::Node?
80
62
  def adjust_for_nested_target(target, parent, position)
81
63
  # If the parent node is not a method call, then make no adjustments
82
64
  return target unless parent.is_a?(Prism::CallNode)
@@ -92,7 +74,7 @@ module RubyLsp
92
74
  arguments.nil? || !node_covers?(arguments, position) ? parent : target
93
75
  end
94
76
 
95
- sig { params(node: Prism::Node, position: T::Hash[Symbol, T.untyped]).returns(T::Boolean) }
77
+ #: (Prism::Node node, Hash[Symbol, untyped] position) -> bool
96
78
  def node_covers?(node, position)
97
79
  location = node.location
98
80
  start_line = location.start_line - 1
@@ -5,32 +5,26 @@ module RubyLsp
5
5
  module Requests
6
6
  module Support
7
7
  class Annotation
8
- extend T::Sig
9
- sig do
10
- params(
11
- arity: T.any(Integer, T::Range[Integer]),
12
- receiver: T::Boolean,
13
- ).void
14
- end
8
+ #: (arity: (Integer | T::Range[Integer]), ?receiver: bool) -> void
15
9
  def initialize(arity:, receiver: false)
16
10
  @arity = arity
17
11
  @receiver = receiver
18
12
  end
19
13
 
20
- sig { params(node: Prism::CallNode).returns(T::Boolean) }
14
+ #: (Prism::CallNode node) -> bool
21
15
  def match?(node)
22
16
  receiver_matches?(node) && arity_matches?(node)
23
17
  end
24
18
 
25
19
  private
26
20
 
27
- sig { params(node: Prism::CallNode).returns(T::Boolean) }
21
+ #: (Prism::CallNode node) -> bool
28
22
  def receiver_matches?(node)
29
23
  node_receiver = node.receiver
30
24
  (node_receiver && @receiver && node_receiver.location.slice == "T") || (!node_receiver && !@receiver)
31
25
  end
32
26
 
33
- sig { params(node: Prism::CallNode).returns(T::Boolean) }
27
+ #: (Prism::CallNode node) -> bool
34
28
  def arity_matches?(node)
35
29
  node_arity = node.arguments&.arguments&.size || 0
36
30