ruby-lsp 0.10.1 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/VERSION +1 -1
  4. data/exe/ruby-lsp-check +1 -1
  5. data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +35 -5
  6. data/lib/ruby_indexer/lib/ruby_indexer/index.rb +141 -5
  7. data/lib/ruby_indexer/lib/ruby_indexer/visitor.rb +66 -18
  8. data/lib/ruby_indexer/test/classes_and_modules_test.rb +23 -0
  9. data/lib/ruby_indexer/test/configuration_test.rb +2 -0
  10. data/lib/ruby_indexer/test/constant_test.rb +202 -0
  11. data/lib/ruby_indexer/test/index_test.rb +20 -0
  12. data/lib/ruby_lsp/{extension.rb → addon.rb} +27 -25
  13. data/lib/ruby_lsp/check_docs.rb +7 -8
  14. data/lib/ruby_lsp/document.rb +35 -38
  15. data/lib/ruby_lsp/event_emitter.rb +239 -77
  16. data/lib/ruby_lsp/executor.rb +45 -55
  17. data/lib/ruby_lsp/internal.rb +2 -3
  18. data/lib/ruby_lsp/listener.rb +8 -7
  19. data/lib/ruby_lsp/parameter_scope.rb +33 -0
  20. data/lib/ruby_lsp/requests/base_request.rb +3 -3
  21. data/lib/ruby_lsp/requests/code_action_resolve.rb +14 -14
  22. data/lib/ruby_lsp/requests/code_lens.rb +39 -63
  23. data/lib/ruby_lsp/requests/completion.rb +54 -32
  24. data/lib/ruby_lsp/requests/definition.rb +30 -27
  25. data/lib/ruby_lsp/requests/diagnostics.rb +26 -3
  26. data/lib/ruby_lsp/requests/document_highlight.rb +18 -19
  27. data/lib/ruby_lsp/requests/document_link.rb +50 -9
  28. data/lib/ruby_lsp/requests/document_symbol.rb +82 -75
  29. data/lib/ruby_lsp/requests/folding_ranges.rb +199 -222
  30. data/lib/ruby_lsp/requests/formatting.rb +5 -6
  31. data/lib/ruby_lsp/requests/hover.rb +33 -22
  32. data/lib/ruby_lsp/requests/inlay_hints.rb +2 -3
  33. data/lib/ruby_lsp/requests/selection_ranges.rb +65 -40
  34. data/lib/ruby_lsp/requests/semantic_highlighting.rb +187 -145
  35. data/lib/ruby_lsp/requests/show_syntax_tree.rb +3 -4
  36. data/lib/ruby_lsp/requests/support/annotation.rb +18 -17
  37. data/lib/ruby_lsp/requests/support/common.rb +17 -26
  38. data/lib/ruby_lsp/requests/support/dependency_detector.rb +67 -42
  39. data/lib/ruby_lsp/requests/support/highlight_target.rb +64 -45
  40. data/lib/ruby_lsp/requests/support/rubocop_runner.rb +9 -4
  41. data/lib/ruby_lsp/requests/support/selection_range.rb +5 -4
  42. data/lib/ruby_lsp/requests/support/sorbet.rb +2 -57
  43. data/lib/ruby_lsp/requests/support/syntax_tree_formatting_runner.rb +7 -1
  44. data/lib/ruby_lsp/requests/workspace_symbol.rb +4 -1
  45. data/lib/ruby_lsp/server.rb +6 -44
  46. data/lib/ruby_lsp/utils.rb +2 -12
  47. metadata +11 -30
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module RubyLsp
5
- # EventEmitter is an intermediary between our requests and Syntax Tree visitors. It's used to visit the document's AST
5
+ # EventEmitter is an intermediary between our requests and YARP visitors. It's used to visit the document's AST
6
6
  # and emit events that the requests can listen to for providing functionality. Usages:
7
7
  #
8
8
  # - For positional requests, locate the target node and use `emit_for_target` to fire events for each listener
@@ -18,9 +18,8 @@ module RubyLsp
18
18
  # emitter.emit_for_target(target_node)
19
19
  # listener.response
20
20
  # ```
21
- class EventEmitter < SyntaxTree::Visitor
21
+ class EventEmitter < YARP::Visitor
22
22
  extend T::Sig
23
- include SyntaxTree::WithScope
24
23
 
25
24
  sig { void }
26
25
  def initialize
@@ -35,154 +34,317 @@ module RubyLsp
35
34
 
36
35
  # Emit events for a specific node. This is similar to the regular `visit` method, but avoids going deeper into the
37
36
  # tree for performance
38
- sig { params(node: T.nilable(SyntaxTree::Node)).void }
37
+ sig { params(node: T.nilable(YARP::Node)).void }
39
38
  def emit_for_target(node)
40
39
  case node
41
- when SyntaxTree::Command
42
- @listeners[:on_command]&.each { |l| T.unsafe(l).on_command(node) }
43
- when SyntaxTree::CallNode
40
+ when YARP::CallNode
44
41
  @listeners[:on_call]&.each { |l| T.unsafe(l).on_call(node) }
45
- when SyntaxTree::TStringContent
46
- @listeners[:on_tstring_content]&.each { |l| T.unsafe(l).on_tstring_content(node) }
47
- when SyntaxTree::ConstPathRef
48
- @listeners[:on_const_path_ref]&.each { |l| T.unsafe(l).on_const_path_ref(node) }
49
- when SyntaxTree::Const
50
- @listeners[:on_const]&.each { |l| T.unsafe(l).on_const(node) }
51
- when SyntaxTree::TopConstRef
52
- @listeners[:on_top_const_ref]&.each { |l| T.unsafe(l).on_top_const_ref(node) }
42
+ when YARP::ConstantPathNode
43
+ @listeners[:on_constant_path]&.each { |l| T.unsafe(l).on_constant_path(node) }
44
+ when YARP::StringNode
45
+ @listeners[:on_string]&.each { |l| T.unsafe(l).on_string(node) }
46
+ when YARP::ClassNode
47
+ @listeners[:on_class]&.each { |l| T.unsafe(l).on_class(node) }
48
+ when YARP::ModuleNode
49
+ @listeners[:on_module]&.each { |l| T.unsafe(l).on_module(node) }
50
+ when YARP::ConstantWriteNode
51
+ @listeners[:on_constant_write]&.each { |l| T.unsafe(l).on_constant_write(node) }
52
+ when YARP::ConstantReadNode
53
+ @listeners[:on_constant_read]&.each { |l| T.unsafe(l).on_constant_read(node) }
53
54
  end
54
55
  end
55
56
 
56
57
  # Visit dispatchers are below. Notice that for nodes that create a new scope (e.g.: classes, modules, method defs)
57
58
  # we need both an `on_*` and `after_*` event. This is because some requests must know when we exit the scope
58
- sig { override.params(node: T.nilable(SyntaxTree::Node)).void }
59
+ sig { override.params(node: T.nilable(YARP::Node)).void }
59
60
  def visit(node)
60
61
  @listeners[:on_node]&.each { |l| T.unsafe(l).on_node(node) }
61
62
  super
62
63
  end
63
64
 
64
- sig { override.params(node: SyntaxTree::ClassDeclaration).void }
65
- def visit_class(node)
65
+ sig { params(nodes: T::Array[T.nilable(YARP::Node)]).void }
66
+ def visit_all(nodes)
67
+ nodes.each { |node| visit(node) }
68
+ end
69
+
70
+ sig { override.params(node: YARP::ClassNode).void }
71
+ def visit_class_node(node)
66
72
  @listeners[:on_class]&.each { |l| T.unsafe(l).on_class(node) }
67
73
  super
68
74
  @listeners[:after_class]&.each { |l| T.unsafe(l).after_class(node) }
69
75
  end
70
76
 
71
- sig { override.params(node: SyntaxTree::ModuleDeclaration).void }
72
- def visit_module(node)
77
+ sig { override.params(node: YARP::ModuleNode).void }
78
+ def visit_module_node(node)
73
79
  @listeners[:on_module]&.each { |l| T.unsafe(l).on_module(node) }
74
80
  super
75
81
  @listeners[:after_module]&.each { |l| T.unsafe(l).after_module(node) }
76
82
  end
77
83
 
78
- sig { override.params(node: SyntaxTree::Command).void }
79
- def visit_command(node)
80
- @listeners[:on_command]&.each { |l| T.unsafe(l).on_command(node) }
84
+ sig { override.params(node: YARP::CallNode).void }
85
+ def visit_call_node(node)
86
+ @listeners[:on_call]&.each { |l| T.unsafe(l).on_call(node) }
81
87
  super
82
- @listeners[:after_command]&.each { |l| T.unsafe(l).after_command(node) }
88
+ @listeners[:after_call]&.each { |l| T.unsafe(l).after_call(node) }
83
89
  end
84
90
 
85
- sig { override.params(node: SyntaxTree::CommandCall).void }
86
- def visit_command_call(node)
87
- @listeners[:on_command_call]&.each { |l| T.unsafe(l).on_command_call(node) }
91
+ sig { override.params(node: YARP::InstanceVariableWriteNode).void }
92
+ def visit_instance_variable_write_node(node)
93
+ @listeners[:on_instance_variable_write]&.each { |l| T.unsafe(l).on_instance_variable_write(node) }
88
94
  super
89
95
  end
90
96
 
91
- sig { override.params(node: SyntaxTree::CallNode).void }
92
- def visit_call(node)
93
- @listeners[:on_call]&.each { |l| T.unsafe(l).on_call(node) }
97
+ sig { override.params(node: YARP::ClassVariableWriteNode).void }
98
+ def visit_class_variable_write_node(node)
99
+ @listeners[:on_class_variable_write]&.each { |l| T.unsafe(l).on_class_variable_write(node) }
94
100
  super
95
- @listeners[:after_call]&.each { |l| T.unsafe(l).after_call(node) }
96
101
  end
97
102
 
98
- sig { override.params(node: SyntaxTree::VCall).void }
99
- def visit_vcall(node)
100
- @listeners[:on_vcall]&.each { |l| T.unsafe(l).on_vcall(node) }
103
+ sig { override.params(node: YARP::DefNode).void }
104
+ def visit_def_node(node)
105
+ @listeners[:on_def]&.each { |l| T.unsafe(l).on_def(node) }
101
106
  super
107
+ @listeners[:after_def]&.each { |l| T.unsafe(l).after_def(node) }
102
108
  end
103
109
 
104
- sig { override.params(node: SyntaxTree::ConstPathField).void }
105
- def visit_const_path_field(node)
106
- @listeners[:on_const_path_field]&.each { |l| T.unsafe(l).on_const_path_field(node) }
110
+ sig { override.params(node: YARP::BlockNode).void }
111
+ def visit_block_node(node)
112
+ @listeners[:on_block]&.each { |l| T.unsafe(l).on_block(node) }
107
113
  super
114
+ @listeners[:after_block]&.each { |l| T.unsafe(l).after_block(node) }
108
115
  end
109
116
 
110
- sig { override.params(node: SyntaxTree::TopConstField).void }
111
- def visit_top_const_field(node)
112
- @listeners[:on_top_const_field]&.each { |l| T.unsafe(l).on_top_const_field(node) }
117
+ sig { override.params(node: YARP::SelfNode).void }
118
+ def visit_self_node(node)
119
+ @listeners[:on_self]&.each { |l| T.unsafe(l).on_self(node) }
113
120
  super
114
121
  end
115
122
 
116
- sig { override.params(node: SyntaxTree::DefNode).void }
117
- def visit_def(node)
118
- @listeners[:on_def]&.each { |l| T.unsafe(l).on_def(node) }
123
+ sig { override.params(node: YARP::RescueNode).void }
124
+ def visit_rescue_node(node)
125
+ @listeners[:on_rescue]&.each { |l| T.unsafe(l).on_rescue(node) }
119
126
  super
120
- @listeners[:after_def]&.each { |l| T.unsafe(l).after_def(node) }
121
127
  end
122
128
 
123
- sig { override.params(node: SyntaxTree::VarField).void }
124
- def visit_var_field(node)
125
- @listeners[:on_var_field]&.each { |l| T.unsafe(l).on_var_field(node) }
129
+ sig { override.params(node: YARP::BlockParameterNode).void }
130
+ def visit_block_parameter_node(node)
131
+ @listeners[:on_block_parameter]&.each { |l| T.unsafe(l).on_block_parameter(node) }
126
132
  super
127
133
  end
128
134
 
129
- sig { override.params(node: SyntaxTree::Comment).void }
130
- def visit_comment(node)
131
- @listeners[:on_comment]&.each { |l| T.unsafe(l).on_comment(node) }
135
+ sig { override.params(node: YARP::KeywordParameterNode).void }
136
+ def visit_keyword_parameter_node(node)
137
+ @listeners[:on_keyword_parameter]&.each { |l| T.unsafe(l).on_keyword_parameter(node) }
132
138
  super
133
139
  end
134
140
 
135
- sig { override.params(node: SyntaxTree::Rescue).void }
136
- def visit_rescue(node)
137
- @listeners[:on_rescue]&.each { |l| T.unsafe(l).on_rescue(node) }
141
+ sig { override.params(node: YARP::KeywordRestParameterNode).void }
142
+ def visit_keyword_rest_parameter_node(node)
143
+ @listeners[:on_keyword_rest_parameter]&.each { |l| T.unsafe(l).on_keyword_rest_parameter(node) }
144
+ super
145
+ end
146
+
147
+ sig { override.params(node: YARP::OptionalParameterNode).void }
148
+ def visit_optional_parameter_node(node)
149
+ @listeners[:on_optional_parameter]&.each { |l| T.unsafe(l).on_optional_parameter(node) }
150
+ super
151
+ end
152
+
153
+ sig { override.params(node: YARP::RequiredParameterNode).void }
154
+ def visit_required_parameter_node(node)
155
+ @listeners[:on_required_parameter]&.each { |l| T.unsafe(l).on_required_parameter(node) }
156
+ super
157
+ end
158
+
159
+ sig { override.params(node: YARP::RestParameterNode).void }
160
+ def visit_rest_parameter_node(node)
161
+ @listeners[:on_rest_parameter]&.each { |l| T.unsafe(l).on_rest_parameter(node) }
162
+ super
163
+ end
164
+
165
+ sig { override.params(node: YARP::ConstantReadNode).void }
166
+ def visit_constant_read_node(node)
167
+ @listeners[:on_constant_read]&.each { |l| T.unsafe(l).on_constant_read(node) }
168
+ super
169
+ end
170
+
171
+ sig { override.params(node: YARP::ConstantPathNode).void }
172
+ def visit_constant_path_node(node)
173
+ @listeners[:on_constant_path]&.each { |l| T.unsafe(l).on_constant_path(node) }
174
+ super
175
+ end
176
+
177
+ sig { override.params(node: YARP::ConstantPathWriteNode).void }
178
+ def visit_constant_path_write_node(node)
179
+ @listeners[:on_constant_path_write]&.each { |l| T.unsafe(l).on_constant_path_write(node) }
180
+ super
181
+ end
182
+
183
+ sig { override.params(node: YARP::ConstantWriteNode).void }
184
+ def visit_constant_write_node(node)
185
+ @listeners[:on_constant_write]&.each { |l| T.unsafe(l).on_constant_write(node) }
186
+ super
187
+ end
188
+
189
+ sig { override.params(node: YARP::ConstantAndWriteNode).void }
190
+ def visit_constant_and_write_node(node)
191
+ @listeners[:on_constant_and_write]&.each { |l| T.unsafe(l).on_constant_and_write(node) }
192
+ super
193
+ end
194
+
195
+ sig { override.params(node: YARP::ConstantOperatorWriteNode).void }
196
+ def visit_constant_operator_write_node(node)
197
+ @listeners[:on_constant_operator_write]&.each { |l| T.unsafe(l).on_constant_operator_write(node) }
198
+ super
199
+ end
200
+
201
+ sig { override.params(node: YARP::ConstantOrWriteNode).void }
202
+ def visit_constant_or_write_node(node)
203
+ @listeners[:on_constant_or_write]&.each { |l| T.unsafe(l).on_constant_or_write(node) }
204
+ super
205
+ end
206
+
207
+ sig { override.params(node: YARP::ConstantTargetNode).void }
208
+ def visit_constant_target_node(node)
209
+ @listeners[:on_constant_target]&.each { |l| T.unsafe(l).on_constant_target(node) }
210
+ super
211
+ end
212
+
213
+ sig { override.params(node: YARP::LocalVariableWriteNode).void }
214
+ def visit_local_variable_write_node(node)
215
+ @listeners[:on_local_variable_write]&.each { |l| T.unsafe(l).on_local_variable_write(node) }
216
+ super
217
+ end
218
+
219
+ sig { override.params(node: YARP::LocalVariableReadNode).void }
220
+ def visit_local_variable_read_node(node)
221
+ @listeners[:on_local_variable_read]&.each { |l| T.unsafe(l).on_local_variable_read(node) }
222
+ super
223
+ end
224
+
225
+ sig { override.params(node: YARP::LocalVariableAndWriteNode).void }
226
+ def visit_local_variable_and_write_node(node)
227
+ @listeners[:on_local_variable_and_write]&.each { |l| T.unsafe(l).on_local_variable_and_write(node) }
228
+ super
229
+ end
230
+
231
+ sig { override.params(node: YARP::LocalVariableOperatorWriteNode).void }
232
+ def visit_local_variable_operator_write_node(node)
233
+ @listeners[:on_local_variable_operator_write]&.each { |l| T.unsafe(l).on_local_variable_operator_write(node) }
234
+ super
235
+ end
236
+
237
+ sig { override.params(node: YARP::LocalVariableOrWriteNode).void }
238
+ def visit_local_variable_or_write_node(node)
239
+ @listeners[:on_local_variable_or_write]&.each { |l| T.unsafe(l).on_local_variable_or_write(node) }
240
+ super
241
+ end
242
+
243
+ sig { override.params(node: YARP::LocalVariableTargetNode).void }
244
+ def visit_local_variable_target_node(node)
245
+ @listeners[:on_local_variable_target]&.each { |l| T.unsafe(l).on_local_variable_target(node) }
246
+ super
247
+ end
248
+
249
+ sig { override.params(node: YARP::BlockLocalVariableNode).void }
250
+ def visit_block_local_variable_node(node)
251
+ @listeners[:on_block_local_variable]&.each { |l| T.unsafe(l).on_block_local_variable(node) }
252
+ super
253
+ end
254
+
255
+ sig { override.params(node: YARP::IfNode).void }
256
+ def visit_if_node(node)
257
+ @listeners[:on_if]&.each { |l| T.unsafe(l).on_if(node) }
258
+ super
259
+ end
260
+
261
+ sig { override.params(node: YARP::InNode).void }
262
+ def visit_in_node(node)
263
+ @listeners[:on_in]&.each { |l| T.unsafe(l).on_in(node) }
264
+ super
265
+ end
266
+
267
+ sig { override.params(node: YARP::WhenNode).void }
268
+ def visit_when_node(node)
269
+ @listeners[:on_when]&.each { |l| T.unsafe(l).on_when(node) }
270
+ super
271
+ end
272
+
273
+ sig { override.params(node: YARP::InterpolatedStringNode).void }
274
+ def visit_interpolated_string_node(node)
275
+ @listeners[:on_interpolated_string]&.each { |l| T.unsafe(l).on_interpolated_string(node) }
276
+ super
277
+ end
278
+
279
+ sig { override.params(node: YARP::ArrayNode).void }
280
+ def visit_array_node(node)
281
+ @listeners[:on_array]&.each { |l| T.unsafe(l).on_array(node) }
282
+ super
283
+ end
284
+
285
+ sig { override.params(node: YARP::CaseNode).void }
286
+ def visit_case_node(node)
287
+ @listeners[:on_case]&.each { |l| T.unsafe(l).on_case(node) }
288
+ super
289
+ end
290
+
291
+ sig { override.params(node: YARP::ForNode).void }
292
+ def visit_for_node(node)
293
+ @listeners[:on_for]&.each { |l| T.unsafe(l).on_for(node) }
294
+ super
295
+ end
296
+
297
+ sig { override.params(node: YARP::HashNode).void }
298
+ def visit_hash_node(node)
299
+ @listeners[:on_hash]&.each { |l| T.unsafe(l).on_hash(node) }
138
300
  super
139
301
  end
140
302
 
141
- sig { override.params(node: SyntaxTree::Kw).void }
142
- def visit_kw(node)
143
- @listeners[:on_kw]&.each { |l| T.unsafe(l).on_kw(node) }
303
+ sig { override.params(node: YARP::SingletonClassNode).void }
304
+ def visit_singleton_class_node(node)
305
+ @listeners[:on_singleton_class]&.each { |l| T.unsafe(l).on_singleton_class(node) }
144
306
  super
145
307
  end
146
308
 
147
- sig { override.params(node: SyntaxTree::Params).void }
148
- def visit_params(node)
149
- @listeners[:on_params]&.each { |l| T.unsafe(l).on_params(node) }
309
+ sig { override.params(node: YARP::UnlessNode).void }
310
+ def visit_unless_node(node)
311
+ @listeners[:on_unless]&.each { |l| T.unsafe(l).on_unless(node) }
150
312
  super
151
313
  end
152
314
 
153
- sig { override.params(node: SyntaxTree::Field).void }
154
- def visit_field(node)
155
- @listeners[:on_field]&.each { |l| T.unsafe(l).on_field(node) }
315
+ sig { override.params(node: YARP::UntilNode).void }
316
+ def visit_until_node(node)
317
+ @listeners[:on_until]&.each { |l| T.unsafe(l).on_until(node) }
156
318
  super
157
319
  end
158
320
 
159
- sig { override.params(node: SyntaxTree::VarRef).void }
160
- def visit_var_ref(node)
161
- @listeners[:on_var_ref]&.each { |l| T.unsafe(l).on_var_ref(node) }
321
+ sig { override.params(node: YARP::WhileNode).void }
322
+ def visit_while_node(node)
323
+ @listeners[:on_while]&.each { |l| T.unsafe(l).on_while(node) }
162
324
  super
163
325
  end
164
326
 
165
- sig { override.params(node: SyntaxTree::BlockVar).void }
166
- def visit_block_var(node)
167
- @listeners[:on_block_var]&.each { |l| T.unsafe(l).on_block_var(node) }
327
+ sig { override.params(node: YARP::ElseNode).void }
328
+ def visit_else_node(node)
329
+ @listeners[:on_else]&.each { |l| T.unsafe(l).on_else(node) }
168
330
  super
169
331
  end
170
332
 
171
- sig { override.params(node: SyntaxTree::LambdaVar).void }
172
- def visit_lambda_var(node)
173
- @listeners[:on_lambda_var]&.each { |l| T.unsafe(l).on_lambda_var(node) }
333
+ sig { override.params(node: YARP::EnsureNode).void }
334
+ def visit_ensure_node(node)
335
+ @listeners[:on_ensure]&.each { |l| T.unsafe(l).on_ensure(node) }
174
336
  super
175
337
  end
176
338
 
177
- sig { override.params(node: SyntaxTree::Binary).void }
178
- def visit_binary(node)
339
+ sig { override.params(node: YARP::BeginNode).void }
340
+ def visit_begin_node(node)
341
+ @listeners[:on_begin]&.each { |l| T.unsafe(l).on_begin(node) }
179
342
  super
180
- @listeners[:after_binary]&.each { |l| T.unsafe(l).after_binary(node) }
181
343
  end
182
344
 
183
- sig { override.params(node: SyntaxTree::Const).void }
184
- def visit_const(node)
185
- @listeners[:on_const]&.each { |l| T.unsafe(l).on_const(node) }
345
+ sig { override.params(node: YARP::StringConcatNode).void }
346
+ def visit_string_concat_node(node)
347
+ @listeners[:on_string_concat]&.each { |l| T.unsafe(l).on_string_concat(node) }
186
348
  super
187
349
  end
188
350
  end
@@ -13,7 +13,6 @@ module RubyLsp
13
13
  # Requests that mutate the store must be run sequentially! Parallel requests only receive a temporary copy of the
14
14
  # store
15
15
  @store = store
16
- @test_library = T.let(DependencyDetector.detected_test_library, String)
17
16
  @message_queue = message_queue
18
17
  @index = T.let(RubyIndexer::Index.new, RubyIndexer::Index)
19
18
  end
@@ -23,13 +22,13 @@ module RubyLsp
23
22
  response = T.let(nil, T.untyped)
24
23
  error = T.let(nil, T.nilable(Exception))
25
24
 
26
- request_time = Benchmark.realtime do
25
+ begin
27
26
  response = run(request)
28
27
  rescue StandardError, LoadError => e
29
28
  error = e
30
29
  end
31
30
 
32
- Result.new(response: response, error: error, request_time: request_time)
31
+ Result.new(response: response, error: error)
33
32
  end
34
33
 
35
34
  private
@@ -42,20 +41,20 @@ module RubyLsp
42
41
  when "initialize"
43
42
  initialize_request(request.dig(:params))
44
43
  when "initialized"
45
- Extension.load_extensions
44
+ Addon.load_addons
46
45
 
47
- errored_extensions = Extension.extensions.select(&:error?)
46
+ errored_addons = Addon.addons.select(&:error?)
48
47
 
49
- if errored_extensions.any?
48
+ if errored_addons.any?
50
49
  @message_queue << Notification.new(
51
50
  message: "window/showMessage",
52
51
  params: Interface::ShowMessageParams.new(
53
52
  type: Constant::MessageType::WARNING,
54
- message: "Error loading extensions:\n\n#{errored_extensions.map(&:formatted_errors).join("\n\n")}",
53
+ message: "Error loading addons:\n\n#{errored_addons.map(&:formatted_errors).join("\n\n")}",
55
54
  ),
56
55
  )
57
56
 
58
- warn(errored_extensions.map(&:backtraces).join("\n\n"))
57
+ warn(errored_addons.map(&:backtraces).join("\n\n"))
59
58
  end
60
59
 
61
60
  perform_initial_indexing
@@ -82,12 +81,10 @@ module RubyLsp
82
81
  request.dig(:params, :contentChanges),
83
82
  request.dig(:params, :textDocument, :version),
84
83
  )
85
- when "textDocument/foldingRange"
86
- folding_range(uri)
87
84
  when "textDocument/selectionRange"
88
85
  selection_range(uri, request.dig(:params, :positions))
89
86
  when "textDocument/documentSymbol", "textDocument/documentLink", "textDocument/codeLens",
90
- "textDocument/semanticTokens/full"
87
+ "textDocument/semanticTokens/full", "textDocument/foldingRange"
91
88
  document = @store.get(uri)
92
89
 
93
90
  # If the response has already been cached by another request, return it
@@ -96,15 +93,17 @@ module RubyLsp
96
93
 
97
94
  # Run listeners for the document
98
95
  emitter = EventEmitter.new
96
+ folding_range = Requests::FoldingRanges.new(document.parse_result.comments, emitter, @message_queue)
99
97
  document_symbol = Requests::DocumentSymbol.new(emitter, @message_queue)
100
- document_link = Requests::DocumentLink.new(uri, emitter, @message_queue)
101
- code_lens = Requests::CodeLens.new(uri, emitter, @message_queue, @test_library)
98
+ document_link = Requests::DocumentLink.new(uri, document.comments, emitter, @message_queue)
99
+ code_lens = Requests::CodeLens.new(uri, emitter, @message_queue)
102
100
 
103
101
  semantic_highlighting = Requests::SemanticHighlighting.new(emitter, @message_queue)
104
- emitter.visit(document.tree) if document.parsed?
102
+ emitter.visit(document.tree)
105
103
 
106
104
  # Store all responses retrieve in this round of visits in the cache and then return the response for the request
107
105
  # we actually received
106
+ document.cache_set("textDocument/foldingRange", folding_range.response)
108
107
  document.cache_set("textDocument/documentSymbol", document_symbol.response)
109
108
  document.cache_set("textDocument/documentLink", document_link.response)
110
109
  document.cache_set("textDocument/codeLens", code_lens.response)
@@ -246,28 +245,25 @@ module RubyLsp
246
245
  end
247
246
  def definition(uri, position)
248
247
  document = @store.get(uri)
249
- return if document.syntax_error?
250
-
251
248
  target, parent, nesting = document.locate_node(
252
249
  position,
253
- node_types: [SyntaxTree::Command, SyntaxTree::Const, SyntaxTree::ConstPathRef],
250
+ node_types: [YARP::CallNode, YARP::ConstantReadNode, YARP::ConstantPathNode],
254
251
  )
255
252
 
256
- target = parent if target.is_a?(SyntaxTree::Const) && parent.is_a?(SyntaxTree::ConstPathRef)
253
+ target = parent if target.is_a?(YARP::ConstantReadNode) && parent.is_a?(YARP::ConstantPathNode)
257
254
 
258
255
  emitter = EventEmitter.new
259
- base_listener = Requests::Definition.new(uri, nesting, @index, emitter, @message_queue)
256
+ base_listener = Requests::Definition.new(
257
+ uri,
258
+ nesting,
259
+ @index,
260
+ emitter,
261
+ @message_queue,
262
+ )
260
263
  emitter.emit_for_target(target)
261
264
  base_listener.response
262
265
  end
263
266
 
264
- sig { params(uri: URI::Generic).returns(T::Array[Interface::FoldingRange]) }
265
- def folding_range(uri)
266
- @store.cache_fetch(uri, "textDocument/foldingRange") do |document|
267
- Requests::FoldingRanges.new(document).run
268
- end
269
- end
270
-
271
267
  sig do
272
268
  params(
273
269
  uri: URI::Generic,
@@ -276,8 +272,6 @@ module RubyLsp
276
272
  end
277
273
  def hover(uri, position)
278
274
  document = @store.get(uri)
279
- return if document.syntax_error?
280
-
281
275
  target, parent, nesting = document.locate_node(
282
276
  position,
283
277
  node_types: Requests::Hover::ALLOWED_TARGETS,
@@ -285,7 +279,7 @@ module RubyLsp
285
279
 
286
280
  if (Requests::Hover::ALLOWED_TARGETS.include?(parent.class) &&
287
281
  !Requests::Hover::ALLOWED_TARGETS.include?(target.class)) ||
288
- (parent.is_a?(SyntaxTree::ConstPathRef) && target.is_a?(SyntaxTree::Const))
282
+ (parent.is_a?(YARP::ConstantPathNode) && target.is_a?(YARP::ConstantReadNode))
289
283
  target = parent
290
284
  end
291
285
 
@@ -371,7 +365,6 @@ module RubyLsp
371
365
  end
372
366
  def document_highlight(uri, position)
373
367
  document = @store.get(uri)
374
- return if document.syntax_error?
375
368
 
376
369
  target, parent = document.locate_node(position)
377
370
  emitter = EventEmitter.new
@@ -383,7 +376,6 @@ module RubyLsp
383
376
  sig { params(uri: URI::Generic, range: Document::RangeShape).returns(T.nilable(T::Array[Interface::InlayHint])) }
384
377
  def inlay_hint(uri, range)
385
378
  document = @store.get(uri)
386
- return if document.syntax_error?
387
379
 
388
380
  start_line = range.dig(:start, :line)
389
381
  end_line = range.dig(:end, :line)
@@ -443,7 +435,7 @@ module RubyLsp
443
435
  Requests::Diagnostics.new(document).run
444
436
  end
445
437
 
446
- Interface::FullDocumentDiagnosticReport.new(kind: "full", items: response.map(&:to_lsp_diagnostic)) if response
438
+ Interface::FullDocumentDiagnosticReport.new(kind: "full", items: response) if response
447
439
  end
448
440
 
449
441
  sig { params(uri: URI::Generic, range: Document::RangeShape).returns(Interface::SemanticTokens) }
@@ -458,7 +450,7 @@ module RubyLsp
458
450
  @message_queue,
459
451
  range: start_line..end_line,
460
452
  )
461
- emitter.visit(document.tree) if document.parsed?
453
+ emitter.visit(document.tree)
462
454
 
463
455
  Requests::Support::SemanticTokenEncoder.new.encode(listener.response)
464
456
  end
@@ -471,7 +463,6 @@ module RubyLsp
471
463
  end
472
464
  def completion(uri, position)
473
465
  document = @store.get(uri)
474
- return unless document.parsed?
475
466
 
476
467
  char_position = document.create_scanner.find_char_position(position)
477
468
 
@@ -480,35 +471,29 @@ module RubyLsp
480
471
  # the node, as it could not be a constant
481
472
  target_node_types = if ("A".."Z").cover?(document.source[char_position - 1])
482
473
  char_position -= 1
483
- [SyntaxTree::Const, SyntaxTree::ConstPathRef, SyntaxTree::TopConstRef]
474
+ [YARP::ConstantReadNode, YARP::ConstantPathNode]
484
475
  else
485
- [SyntaxTree::Command, SyntaxTree::CommandCall, SyntaxTree::CallNode]
476
+ [YARP::CallNode]
486
477
  end
487
478
 
488
- matched, parent, nesting = document.locate(T.must(document.tree), char_position, node_types: target_node_types)
479
+ matched, parent, nesting = document.locate(document.tree, char_position, node_types: target_node_types)
489
480
  return unless matched && parent
490
481
 
491
482
  target = case matched
492
- when SyntaxTree::Command, SyntaxTree::CallNode, SyntaxTree::CommandCall
483
+ when YARP::CallNode
493
484
  message = matched.message
494
- return if message.is_a?(Symbol)
495
- return unless message.value == "require"
496
-
497
- args = matched.arguments
498
- args = args.arguments if args.is_a?(SyntaxTree::ArgParen)
499
- return if args.nil? || args.is_a?(SyntaxTree::ArgsForward)
485
+ return unless message == "require"
500
486
 
501
- argument = args.parts.first
502
- return unless argument.is_a?(SyntaxTree::StringLiteral)
487
+ args = matched.arguments&.arguments
488
+ return if args.nil? || args.is_a?(YARP::ForwardingArgumentsNode)
503
489
 
504
- path_node = argument.parts.first
505
- return unless path_node.is_a?(SyntaxTree::TStringContent)
506
- return unless (path_node.location.start_char..path_node.location.end_char).cover?(char_position)
490
+ argument = args.first
491
+ return unless argument.is_a?(YARP::StringNode)
492
+ return unless (argument.location.start_offset..argument.location.end_offset).cover?(char_position)
507
493
 
508
- path_node
509
- when SyntaxTree::Const, SyntaxTree::ConstPathRef
510
- if (parent.is_a?(SyntaxTree::ConstPathRef) || parent.is_a?(SyntaxTree::TopConstRef)) &&
511
- matched.is_a?(SyntaxTree::Const)
494
+ argument
495
+ when YARP::ConstantReadNode, YARP::ConstantPathNode
496
+ if parent.is_a?(YARP::ConstantPathNode) && matched.is_a?(YARP::ConstantReadNode)
512
497
  parent
513
498
  else
514
499
  matched
@@ -518,7 +503,12 @@ module RubyLsp
518
503
  return unless target
519
504
 
520
505
  emitter = EventEmitter.new
521
- listener = Requests::Completion.new(@index, nesting, emitter, @message_queue)
506
+ listener = Requests::Completion.new(
507
+ @index,
508
+ nesting,
509
+ emitter,
510
+ @message_queue,
511
+ )
522
512
  emitter.emit_for_target(target)
523
513
  listener.response
524
514
  end
@@ -570,7 +560,7 @@ module RubyLsp
570
560
  @store.supports_progress = options.dig(:capabilities, :window, :workDoneProgress) || true
571
561
  formatter = options.dig(:initializationOptions, :formatter) || "auto"
572
562
  @store.formatter = if formatter == "auto"
573
- DependencyDetector.detected_formatter
563
+ DependencyDetector.instance.detected_formatter
574
564
  else
575
565
  formatter
576
566
  end