ruby-lsp 0.11.2 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/exe/ruby-lsp +2 -1
- data/exe/ruby-lsp-doctor +16 -0
- data/lib/ruby_indexer/lib/ruby_indexer/configuration.rb +5 -1
- data/lib/ruby_indexer/lib/ruby_indexer/entry.rb +205 -0
- data/lib/ruby_indexer/lib/ruby_indexer/index.rb +23 -106
- data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +6 -6
- data/lib/ruby_indexer/lib/ruby_indexer/visitor.rb +101 -49
- data/lib/ruby_indexer/ruby_indexer.rb +1 -0
- data/lib/ruby_indexer/test/classes_and_modules_test.rb +49 -16
- data/lib/ruby_indexer/test/constant_test.rb +99 -36
- data/lib/ruby_indexer/test/index_test.rb +1 -1
- data/lib/ruby_indexer/test/method_test.rb +73 -0
- data/lib/ruby_indexer/test/test_case.rb +5 -1
- data/lib/ruby_lsp/addon.rb +8 -8
- data/lib/ruby_lsp/document.rb +14 -14
- data/lib/ruby_lsp/executor.rb +89 -53
- data/lib/ruby_lsp/internal.rb +7 -2
- data/lib/ruby_lsp/listener.rb +6 -6
- data/lib/ruby_lsp/requests/base_request.rb +1 -9
- data/lib/ruby_lsp/requests/code_action_resolve.rb +3 -3
- data/lib/ruby_lsp/requests/code_lens.rb +30 -30
- data/lib/ruby_lsp/requests/completion.rb +83 -32
- data/lib/ruby_lsp/requests/definition.rb +21 -15
- data/lib/ruby_lsp/requests/diagnostics.rb +1 -1
- data/lib/ruby_lsp/requests/document_highlight.rb +508 -31
- data/lib/ruby_lsp/requests/document_link.rb +24 -17
- data/lib/ruby_lsp/requests/document_symbol.rb +42 -42
- data/lib/ruby_lsp/requests/folding_ranges.rb +83 -77
- data/lib/ruby_lsp/requests/hover.rb +22 -17
- data/lib/ruby_lsp/requests/inlay_hints.rb +6 -6
- data/lib/ruby_lsp/requests/selection_ranges.rb +13 -105
- data/lib/ruby_lsp/requests/semantic_highlighting.rb +92 -92
- data/lib/ruby_lsp/requests/support/annotation.rb +3 -3
- data/lib/ruby_lsp/requests/support/common.rb +5 -5
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +12 -0
- data/lib/ruby_lsp/requests/support/semantic_token_encoder.rb +10 -7
- data/lib/ruby_lsp/requests/support/sorbet.rb +28 -28
- data/lib/ruby_lsp/requests/workspace_symbol.rb +4 -4
- data/lib/ruby_lsp/requests.rb +0 -1
- data/lib/ruby_lsp/setup_bundler.rb +8 -5
- metadata +19 -17
- data/lib/ruby_lsp/event_emitter.rb +0 -351
- data/lib/ruby_lsp/requests/support/highlight_target.rb +0 -118
@@ -27,19 +27,97 @@ module RubyLsp
|
|
27
27
|
|
28
28
|
ResponseType = type_member { { fixed: T::Array[Interface::DocumentHighlight] } }
|
29
29
|
|
30
|
+
GLOBAL_VARIABLE_NODES = T.let(
|
31
|
+
[
|
32
|
+
Prism::GlobalVariableAndWriteNode,
|
33
|
+
Prism::GlobalVariableOperatorWriteNode,
|
34
|
+
Prism::GlobalVariableOrWriteNode,
|
35
|
+
Prism::GlobalVariableReadNode,
|
36
|
+
Prism::GlobalVariableTargetNode,
|
37
|
+
Prism::GlobalVariableWriteNode,
|
38
|
+
],
|
39
|
+
T::Array[T.class_of(Prism::Node)],
|
40
|
+
)
|
41
|
+
|
42
|
+
INSTANCE_VARIABLE_NODES = T.let(
|
43
|
+
[
|
44
|
+
Prism::InstanceVariableAndWriteNode,
|
45
|
+
Prism::InstanceVariableOperatorWriteNode,
|
46
|
+
Prism::InstanceVariableOrWriteNode,
|
47
|
+
Prism::InstanceVariableReadNode,
|
48
|
+
Prism::InstanceVariableTargetNode,
|
49
|
+
Prism::InstanceVariableWriteNode,
|
50
|
+
],
|
51
|
+
T::Array[T.class_of(Prism::Node)],
|
52
|
+
)
|
53
|
+
|
54
|
+
CONSTANT_NODES = T.let(
|
55
|
+
[
|
56
|
+
Prism::ConstantAndWriteNode,
|
57
|
+
Prism::ConstantOperatorWriteNode,
|
58
|
+
Prism::ConstantOrWriteNode,
|
59
|
+
Prism::ConstantReadNode,
|
60
|
+
Prism::ConstantTargetNode,
|
61
|
+
Prism::ConstantWriteNode,
|
62
|
+
],
|
63
|
+
T::Array[T.class_of(Prism::Node)],
|
64
|
+
)
|
65
|
+
|
66
|
+
CONSTANT_PATH_NODES = T.let(
|
67
|
+
[
|
68
|
+
Prism::ConstantPathAndWriteNode,
|
69
|
+
Prism::ConstantPathNode,
|
70
|
+
Prism::ConstantPathOperatorWriteNode,
|
71
|
+
Prism::ConstantPathOrWriteNode,
|
72
|
+
Prism::ConstantPathTargetNode,
|
73
|
+
Prism::ConstantPathWriteNode,
|
74
|
+
],
|
75
|
+
T::Array[T.class_of(Prism::Node)],
|
76
|
+
)
|
77
|
+
|
78
|
+
CLASS_VARIABLE_NODES = T.let(
|
79
|
+
[
|
80
|
+
Prism::ClassVariableAndWriteNode,
|
81
|
+
Prism::ClassVariableOperatorWriteNode,
|
82
|
+
Prism::ClassVariableOrWriteNode,
|
83
|
+
Prism::ClassVariableReadNode,
|
84
|
+
Prism::ClassVariableTargetNode,
|
85
|
+
Prism::ClassVariableWriteNode,
|
86
|
+
],
|
87
|
+
T::Array[T.class_of(Prism::Node)],
|
88
|
+
)
|
89
|
+
|
90
|
+
LOCAL_NODES = T.let(
|
91
|
+
[
|
92
|
+
Prism::LocalVariableAndWriteNode,
|
93
|
+
Prism::LocalVariableOperatorWriteNode,
|
94
|
+
Prism::LocalVariableOrWriteNode,
|
95
|
+
Prism::LocalVariableReadNode,
|
96
|
+
Prism::LocalVariableTargetNode,
|
97
|
+
Prism::LocalVariableWriteNode,
|
98
|
+
Prism::BlockParameterNode,
|
99
|
+
Prism::RequiredParameterNode,
|
100
|
+
Prism::KeywordParameterNode,
|
101
|
+
Prism::RestParameterNode,
|
102
|
+
Prism::OptionalParameterNode,
|
103
|
+
Prism::KeywordRestParameterNode,
|
104
|
+
],
|
105
|
+
T::Array[T.class_of(Prism::Node)],
|
106
|
+
)
|
107
|
+
|
30
108
|
sig { override.returns(ResponseType) }
|
31
109
|
attr_reader :_response
|
32
110
|
|
33
111
|
sig do
|
34
112
|
params(
|
35
|
-
target: T.nilable(
|
36
|
-
parent: T.nilable(
|
37
|
-
|
113
|
+
target: T.nilable(Prism::Node),
|
114
|
+
parent: T.nilable(Prism::Node),
|
115
|
+
dispatcher: Prism::Dispatcher,
|
38
116
|
message_queue: Thread::Queue,
|
39
117
|
).void
|
40
118
|
end
|
41
|
-
def initialize(target, parent,
|
42
|
-
super(
|
119
|
+
def initialize(target, parent, dispatcher, message_queue)
|
120
|
+
super(dispatcher, message_queue)
|
43
121
|
|
44
122
|
@_response = T.let([], T::Array[Interface::DocumentHighlight])
|
45
123
|
|
@@ -47,42 +125,441 @@ module RubyLsp
|
|
47
125
|
|
48
126
|
highlight_target =
|
49
127
|
case target
|
50
|
-
when
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
128
|
+
when Prism::GlobalVariableReadNode, Prism::GlobalVariableAndWriteNode, Prism::GlobalVariableOperatorWriteNode,
|
129
|
+
Prism::GlobalVariableOrWriteNode, Prism::GlobalVariableTargetNode, Prism::GlobalVariableWriteNode,
|
130
|
+
Prism::InstanceVariableAndWriteNode, Prism::InstanceVariableOperatorWriteNode,
|
131
|
+
Prism::InstanceVariableOrWriteNode, Prism::InstanceVariableReadNode, Prism::InstanceVariableTargetNode,
|
132
|
+
Prism::InstanceVariableWriteNode, Prism::ConstantAndWriteNode, Prism::ConstantOperatorWriteNode,
|
133
|
+
Prism::ConstantOrWriteNode, Prism::ConstantPathAndWriteNode, Prism::ConstantPathNode,
|
134
|
+
Prism::ConstantPathOperatorWriteNode, Prism::ConstantPathOrWriteNode, Prism::ConstantPathTargetNode,
|
135
|
+
Prism::ConstantPathWriteNode, Prism::ConstantReadNode, Prism::ConstantTargetNode, Prism::ConstantWriteNode,
|
136
|
+
Prism::ClassVariableAndWriteNode, Prism::ClassVariableOperatorWriteNode, Prism::ClassVariableOrWriteNode,
|
137
|
+
Prism::ClassVariableReadNode, Prism::ClassVariableTargetNode, Prism::ClassVariableWriteNode,
|
138
|
+
Prism::LocalVariableAndWriteNode, Prism::LocalVariableOperatorWriteNode, Prism::LocalVariableOrWriteNode,
|
139
|
+
Prism::LocalVariableReadNode, Prism::LocalVariableTargetNode, Prism::LocalVariableWriteNode,
|
140
|
+
Prism::CallNode, Prism::BlockParameterNode, Prism::KeywordParameterNode, Prism::KeywordRestParameterNode,
|
141
|
+
Prism::OptionalParameterNode, Prism::RequiredParameterNode, Prism::RestParameterNode
|
142
|
+
target
|
65
143
|
end
|
66
144
|
|
67
|
-
@target = T.let(highlight_target, T.nilable(
|
145
|
+
@target = T.let(highlight_target, T.nilable(Prism::Node))
|
146
|
+
@target_value = T.let(node_value(highlight_target), T.nilable(String))
|
147
|
+
|
148
|
+
if @target && @target_value
|
149
|
+
dispatcher.register(
|
150
|
+
self,
|
151
|
+
:on_call_node_enter,
|
152
|
+
:on_def_node_enter,
|
153
|
+
:on_global_variable_target_node_enter,
|
154
|
+
:on_instance_variable_target_node_enter,
|
155
|
+
:on_constant_path_target_node_enter,
|
156
|
+
:on_constant_target_node_enter,
|
157
|
+
:on_class_variable_target_node_enter,
|
158
|
+
:on_local_variable_target_node_enter,
|
159
|
+
:on_block_parameter_node_enter,
|
160
|
+
:on_required_parameter_node_enter,
|
161
|
+
:on_class_node_enter,
|
162
|
+
:on_module_node_enter,
|
163
|
+
:on_local_variable_read_node_enter,
|
164
|
+
:on_constant_path_node_enter,
|
165
|
+
:on_constant_read_node_enter,
|
166
|
+
:on_instance_variable_read_node_enter,
|
167
|
+
:on_class_variable_read_node_enter,
|
168
|
+
:on_global_variable_read_node_enter,
|
169
|
+
:on_constant_path_write_node_enter,
|
170
|
+
:on_constant_path_or_write_node_enter,
|
171
|
+
:on_constant_path_and_write_node_enter,
|
172
|
+
:on_constant_path_operator_write_node_enter,
|
173
|
+
:on_local_variable_write_node_enter,
|
174
|
+
:on_keyword_parameter_node_enter,
|
175
|
+
:on_rest_parameter_node_enter,
|
176
|
+
:on_optional_parameter_node_enter,
|
177
|
+
:on_keyword_rest_parameter_node_enter,
|
178
|
+
:on_local_variable_and_write_node_enter,
|
179
|
+
:on_local_variable_operator_write_node_enter,
|
180
|
+
:on_local_variable_or_write_node_enter,
|
181
|
+
:on_class_variable_write_node_enter,
|
182
|
+
:on_class_variable_or_write_node_enter,
|
183
|
+
:on_class_variable_operator_write_node_enter,
|
184
|
+
:on_class_variable_and_write_node_enter,
|
185
|
+
:on_constant_write_node_enter,
|
186
|
+
:on_constant_or_write_node_enter,
|
187
|
+
:on_constant_operator_write_node_enter,
|
188
|
+
:on_instance_variable_write_node_enter,
|
189
|
+
:on_constant_and_write_node_enter,
|
190
|
+
:on_instance_variable_or_write_node_enter,
|
191
|
+
:on_instance_variable_and_write_node_enter,
|
192
|
+
:on_instance_variable_operator_write_node_enter,
|
193
|
+
:on_global_variable_write_node_enter,
|
194
|
+
:on_global_variable_or_write_node_enter,
|
195
|
+
:on_global_variable_and_write_node_enter,
|
196
|
+
:on_global_variable_operator_write_node_enter,
|
197
|
+
)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
sig { params(node: Prism::CallNode).void }
|
202
|
+
def on_call_node_enter(node)
|
203
|
+
return unless matches?(node, [Prism::CallNode, Prism::DefNode])
|
204
|
+
|
205
|
+
add_highlight(Constant::DocumentHighlightKind::READ, node.location)
|
206
|
+
end
|
207
|
+
|
208
|
+
sig { params(node: Prism::DefNode).void }
|
209
|
+
def on_def_node_enter(node)
|
210
|
+
return unless matches?(node, [Prism::CallNode, Prism::DefNode])
|
211
|
+
|
212
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
213
|
+
end
|
214
|
+
|
215
|
+
sig { params(node: Prism::GlobalVariableTargetNode).void }
|
216
|
+
def on_global_variable_target_node_enter(node)
|
217
|
+
return unless matches?(node, GLOBAL_VARIABLE_NODES)
|
218
|
+
|
219
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.location)
|
220
|
+
end
|
221
|
+
|
222
|
+
sig { params(node: Prism::InstanceVariableTargetNode).void }
|
223
|
+
def on_instance_variable_target_node_enter(node)
|
224
|
+
return unless matches?(node, INSTANCE_VARIABLE_NODES)
|
225
|
+
|
226
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.location)
|
227
|
+
end
|
228
|
+
|
229
|
+
sig { params(node: Prism::ConstantPathTargetNode).void }
|
230
|
+
def on_constant_path_target_node_enter(node)
|
231
|
+
return unless matches?(node, CONSTANT_PATH_NODES)
|
232
|
+
|
233
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.location)
|
234
|
+
end
|
235
|
+
|
236
|
+
sig { params(node: Prism::ConstantTargetNode).void }
|
237
|
+
def on_constant_target_node_enter(node)
|
238
|
+
return unless matches?(node, CONSTANT_NODES)
|
239
|
+
|
240
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.location)
|
241
|
+
end
|
242
|
+
|
243
|
+
sig { params(node: Prism::ClassVariableTargetNode).void }
|
244
|
+
def on_class_variable_target_node_enter(node)
|
245
|
+
return unless matches?(node, CLASS_VARIABLE_NODES)
|
246
|
+
|
247
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.location)
|
248
|
+
end
|
249
|
+
|
250
|
+
sig { params(node: Prism::LocalVariableTargetNode).void }
|
251
|
+
def on_local_variable_target_node_enter(node)
|
252
|
+
return unless matches?(node, LOCAL_NODES)
|
253
|
+
|
254
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.location)
|
255
|
+
end
|
256
|
+
|
257
|
+
sig { params(node: Prism::BlockParameterNode).void }
|
258
|
+
def on_block_parameter_node_enter(node)
|
259
|
+
return unless matches?(node, LOCAL_NODES)
|
260
|
+
|
261
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.location)
|
262
|
+
end
|
263
|
+
|
264
|
+
sig { params(node: Prism::RequiredParameterNode).void }
|
265
|
+
def on_required_parameter_node_enter(node)
|
266
|
+
return unless matches?(node, LOCAL_NODES)
|
267
|
+
|
268
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.location)
|
269
|
+
end
|
270
|
+
|
271
|
+
sig { params(node: Prism::ClassNode).void }
|
272
|
+
def on_class_node_enter(node)
|
273
|
+
return unless matches?(node, CONSTANT_NODES + CONSTANT_PATH_NODES + [Prism::ClassNode])
|
274
|
+
|
275
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.constant_path.location)
|
276
|
+
end
|
277
|
+
|
278
|
+
sig { params(node: Prism::ModuleNode).void }
|
279
|
+
def on_module_node_enter(node)
|
280
|
+
return unless matches?(node, CONSTANT_NODES + CONSTANT_PATH_NODES + [Prism::ModuleNode])
|
281
|
+
|
282
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.constant_path.location)
|
283
|
+
end
|
284
|
+
|
285
|
+
sig { params(node: Prism::LocalVariableReadNode).void }
|
286
|
+
def on_local_variable_read_node_enter(node)
|
287
|
+
return unless matches?(node, LOCAL_NODES)
|
288
|
+
|
289
|
+
add_highlight(Constant::DocumentHighlightKind::READ, node.location)
|
290
|
+
end
|
291
|
+
|
292
|
+
sig { params(node: Prism::ConstantPathNode).void }
|
293
|
+
def on_constant_path_node_enter(node)
|
294
|
+
return unless matches?(node, CONSTANT_PATH_NODES)
|
295
|
+
|
296
|
+
add_highlight(Constant::DocumentHighlightKind::READ, node.location)
|
297
|
+
end
|
298
|
+
|
299
|
+
sig { params(node: Prism::ConstantReadNode).void }
|
300
|
+
def on_constant_read_node_enter(node)
|
301
|
+
return unless matches?(node, CONSTANT_NODES)
|
302
|
+
|
303
|
+
add_highlight(Constant::DocumentHighlightKind::READ, node.location)
|
304
|
+
end
|
305
|
+
|
306
|
+
sig { params(node: Prism::InstanceVariableReadNode).void }
|
307
|
+
def on_instance_variable_read_node_enter(node)
|
308
|
+
return unless matches?(node, INSTANCE_VARIABLE_NODES)
|
309
|
+
|
310
|
+
add_highlight(Constant::DocumentHighlightKind::READ, node.location)
|
311
|
+
end
|
312
|
+
|
313
|
+
sig { params(node: Prism::ClassVariableReadNode).void }
|
314
|
+
def on_class_variable_read_node_enter(node)
|
315
|
+
return unless matches?(node, CLASS_VARIABLE_NODES)
|
316
|
+
|
317
|
+
add_highlight(Constant::DocumentHighlightKind::READ, node.location)
|
318
|
+
end
|
319
|
+
|
320
|
+
sig { params(node: Prism::GlobalVariableReadNode).void }
|
321
|
+
def on_global_variable_read_node_enter(node)
|
322
|
+
return unless matches?(node, GLOBAL_VARIABLE_NODES)
|
323
|
+
|
324
|
+
add_highlight(Constant::DocumentHighlightKind::READ, node.location)
|
325
|
+
end
|
326
|
+
|
327
|
+
sig { params(node: Prism::ConstantPathWriteNode).void }
|
328
|
+
def on_constant_path_write_node_enter(node)
|
329
|
+
return unless matches?(node, CONSTANT_PATH_NODES)
|
330
|
+
|
331
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.target.location)
|
332
|
+
end
|
333
|
+
|
334
|
+
sig { params(node: Prism::ConstantPathOrWriteNode).void }
|
335
|
+
def on_constant_path_or_write_node_enter(node)
|
336
|
+
return unless matches?(node, CONSTANT_PATH_NODES)
|
337
|
+
|
338
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.target.location)
|
339
|
+
end
|
340
|
+
|
341
|
+
sig { params(node: Prism::ConstantPathAndWriteNode).void }
|
342
|
+
def on_constant_path_and_write_node_enter(node)
|
343
|
+
return unless matches?(node, CONSTANT_PATH_NODES)
|
344
|
+
|
345
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.target.location)
|
346
|
+
end
|
347
|
+
|
348
|
+
sig { params(node: Prism::ConstantPathOperatorWriteNode).void }
|
349
|
+
def on_constant_path_operator_write_node_enter(node)
|
350
|
+
return unless matches?(node, CONSTANT_PATH_NODES)
|
351
|
+
|
352
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.target.location)
|
353
|
+
end
|
354
|
+
|
355
|
+
sig { params(node: Prism::LocalVariableWriteNode).void }
|
356
|
+
def on_local_variable_write_node_enter(node)
|
357
|
+
return unless matches?(node, LOCAL_NODES)
|
358
|
+
|
359
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
360
|
+
end
|
361
|
+
|
362
|
+
sig { params(node: Prism::KeywordParameterNode).void }
|
363
|
+
def on_keyword_parameter_node_enter(node)
|
364
|
+
return unless matches?(node, LOCAL_NODES)
|
68
365
|
|
69
|
-
|
366
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
70
367
|
end
|
71
368
|
|
72
|
-
sig { params(node:
|
73
|
-
def
|
74
|
-
return
|
369
|
+
sig { params(node: Prism::RestParameterNode).void }
|
370
|
+
def on_rest_parameter_node_enter(node)
|
371
|
+
return unless matches?(node, LOCAL_NODES)
|
75
372
|
|
76
|
-
|
77
|
-
add_highlight(
|
373
|
+
name_loc = node.name_loc
|
374
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, name_loc) if name_loc
|
375
|
+
end
|
376
|
+
|
377
|
+
sig { params(node: Prism::OptionalParameterNode).void }
|
378
|
+
def on_optional_parameter_node_enter(node)
|
379
|
+
return unless matches?(node, LOCAL_NODES)
|
380
|
+
|
381
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
382
|
+
end
|
383
|
+
|
384
|
+
sig { params(node: Prism::KeywordRestParameterNode).void }
|
385
|
+
def on_keyword_rest_parameter_node_enter(node)
|
386
|
+
return unless matches?(node, LOCAL_NODES)
|
387
|
+
|
388
|
+
name_loc = node.name_loc
|
389
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, name_loc) if name_loc
|
390
|
+
end
|
391
|
+
|
392
|
+
sig { params(node: Prism::LocalVariableAndWriteNode).void }
|
393
|
+
def on_local_variable_and_write_node_enter(node)
|
394
|
+
return unless matches?(node, LOCAL_NODES)
|
395
|
+
|
396
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
397
|
+
end
|
398
|
+
|
399
|
+
sig { params(node: Prism::LocalVariableOperatorWriteNode).void }
|
400
|
+
def on_local_variable_operator_write_node_enter(node)
|
401
|
+
return unless matches?(node, LOCAL_NODES)
|
402
|
+
|
403
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
404
|
+
end
|
405
|
+
|
406
|
+
sig { params(node: Prism::LocalVariableOrWriteNode).void }
|
407
|
+
def on_local_variable_or_write_node_enter(node)
|
408
|
+
return unless matches?(node, LOCAL_NODES)
|
409
|
+
|
410
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
411
|
+
end
|
412
|
+
|
413
|
+
sig { params(node: Prism::ClassVariableWriteNode).void }
|
414
|
+
def on_class_variable_write_node_enter(node)
|
415
|
+
return unless matches?(node, CLASS_VARIABLE_NODES)
|
416
|
+
|
417
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
418
|
+
end
|
419
|
+
|
420
|
+
sig { params(node: Prism::ClassVariableOrWriteNode).void }
|
421
|
+
def on_class_variable_or_write_node_enter(node)
|
422
|
+
return unless matches?(node, CLASS_VARIABLE_NODES)
|
423
|
+
|
424
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
425
|
+
end
|
426
|
+
|
427
|
+
sig { params(node: Prism::ClassVariableOperatorWriteNode).void }
|
428
|
+
def on_class_variable_operator_write_node_enter(node)
|
429
|
+
return unless matches?(node, CLASS_VARIABLE_NODES)
|
430
|
+
|
431
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
432
|
+
end
|
433
|
+
|
434
|
+
sig { params(node: Prism::ClassVariableAndWriteNode).void }
|
435
|
+
def on_class_variable_and_write_node_enter(node)
|
436
|
+
return unless matches?(node, CLASS_VARIABLE_NODES)
|
437
|
+
|
438
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
439
|
+
end
|
440
|
+
|
441
|
+
sig { params(node: Prism::ConstantWriteNode).void }
|
442
|
+
def on_constant_write_node_enter(node)
|
443
|
+
return unless matches?(node, CONSTANT_NODES)
|
444
|
+
|
445
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
446
|
+
end
|
447
|
+
|
448
|
+
sig { params(node: Prism::ConstantOrWriteNode).void }
|
449
|
+
def on_constant_or_write_node_enter(node)
|
450
|
+
return unless matches?(node, CONSTANT_NODES)
|
451
|
+
|
452
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
453
|
+
end
|
454
|
+
|
455
|
+
sig { params(node: Prism::ConstantOperatorWriteNode).void }
|
456
|
+
def on_constant_operator_write_node_enter(node)
|
457
|
+
return unless matches?(node, CONSTANT_NODES)
|
458
|
+
|
459
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
460
|
+
end
|
461
|
+
|
462
|
+
sig { params(node: Prism::InstanceVariableWriteNode).void }
|
463
|
+
def on_instance_variable_write_node_enter(node)
|
464
|
+
return unless matches?(node, INSTANCE_VARIABLE_NODES)
|
465
|
+
|
466
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
467
|
+
end
|
468
|
+
|
469
|
+
sig { params(node: Prism::InstanceVariableOrWriteNode).void }
|
470
|
+
def on_instance_variable_or_write_node_enter(node)
|
471
|
+
return unless matches?(node, INSTANCE_VARIABLE_NODES)
|
472
|
+
|
473
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
474
|
+
end
|
475
|
+
|
476
|
+
sig { params(node: Prism::InstanceVariableAndWriteNode).void }
|
477
|
+
def on_instance_variable_and_write_node_enter(node)
|
478
|
+
return unless matches?(node, INSTANCE_VARIABLE_NODES)
|
479
|
+
|
480
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
481
|
+
end
|
482
|
+
|
483
|
+
sig { params(node: Prism::InstanceVariableOperatorWriteNode).void }
|
484
|
+
def on_instance_variable_operator_write_node_enter(node)
|
485
|
+
return unless matches?(node, INSTANCE_VARIABLE_NODES)
|
486
|
+
|
487
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
488
|
+
end
|
489
|
+
|
490
|
+
sig { params(node: Prism::ConstantAndWriteNode).void }
|
491
|
+
def on_constant_and_write_node_enter(node)
|
492
|
+
return unless matches?(node, CONSTANT_NODES)
|
493
|
+
|
494
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
495
|
+
end
|
496
|
+
|
497
|
+
sig { params(node: Prism::GlobalVariableWriteNode).void }
|
498
|
+
def on_global_variable_write_node_enter(node)
|
499
|
+
return unless matches?(node, GLOBAL_VARIABLE_NODES)
|
500
|
+
|
501
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
502
|
+
end
|
503
|
+
|
504
|
+
sig { params(node: Prism::GlobalVariableOrWriteNode).void }
|
505
|
+
def on_global_variable_or_write_node_enter(node)
|
506
|
+
return unless matches?(node, GLOBAL_VARIABLE_NODES)
|
507
|
+
|
508
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
509
|
+
end
|
510
|
+
|
511
|
+
sig { params(node: Prism::GlobalVariableAndWriteNode).void }
|
512
|
+
def on_global_variable_and_write_node_enter(node)
|
513
|
+
return unless matches?(node, GLOBAL_VARIABLE_NODES)
|
514
|
+
|
515
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
516
|
+
end
|
517
|
+
|
518
|
+
sig { params(node: Prism::GlobalVariableOperatorWriteNode).void }
|
519
|
+
def on_global_variable_operator_write_node_enter(node)
|
520
|
+
return unless matches?(node, GLOBAL_VARIABLE_NODES)
|
521
|
+
|
522
|
+
add_highlight(Constant::DocumentHighlightKind::WRITE, node.name_loc)
|
78
523
|
end
|
79
524
|
|
80
525
|
private
|
81
526
|
|
82
|
-
sig { params(
|
83
|
-
def
|
84
|
-
|
85
|
-
|
527
|
+
sig { params(node: Prism::Node, classes: T::Array[T.class_of(Prism::Node)]).returns(T.nilable(T::Boolean)) }
|
528
|
+
def matches?(node, classes)
|
529
|
+
classes.any? { |klass| @target.is_a?(klass) } && @target_value == node_value(node)
|
530
|
+
end
|
531
|
+
|
532
|
+
sig { params(kind: Integer, location: Prism::Location).void }
|
533
|
+
def add_highlight(kind, location)
|
534
|
+
@_response << Interface::DocumentHighlight.new(range: range_from_location(location), kind: kind)
|
535
|
+
end
|
536
|
+
|
537
|
+
sig { params(node: T.nilable(Prism::Node)).returns(T.nilable(String)) }
|
538
|
+
def node_value(node)
|
539
|
+
case node
|
540
|
+
when Prism::ConstantReadNode, Prism::ConstantPathNode, Prism::BlockArgumentNode, Prism::ConstantTargetNode,
|
541
|
+
Prism::ConstantPathWriteNode, Prism::ConstantPathTargetNode, Prism::ConstantPathOrWriteNode,
|
542
|
+
Prism::ConstantPathOperatorWriteNode, Prism::ConstantPathAndWriteNode
|
543
|
+
node.slice
|
544
|
+
when Prism::GlobalVariableReadNode, Prism::GlobalVariableAndWriteNode, Prism::GlobalVariableOperatorWriteNode,
|
545
|
+
Prism::GlobalVariableOrWriteNode, Prism::GlobalVariableTargetNode, Prism::GlobalVariableWriteNode,
|
546
|
+
Prism::InstanceVariableAndWriteNode, Prism::InstanceVariableOperatorWriteNode,
|
547
|
+
Prism::InstanceVariableOrWriteNode, Prism::InstanceVariableReadNode, Prism::InstanceVariableTargetNode,
|
548
|
+
Prism::InstanceVariableWriteNode, Prism::ConstantAndWriteNode, Prism::ConstantOperatorWriteNode,
|
549
|
+
Prism::ConstantOrWriteNode, Prism::ConstantWriteNode, Prism::ClassVariableAndWriteNode,
|
550
|
+
Prism::ClassVariableOperatorWriteNode, Prism::ClassVariableOrWriteNode, Prism::ClassVariableReadNode,
|
551
|
+
Prism::ClassVariableTargetNode, Prism::ClassVariableWriteNode, Prism::LocalVariableAndWriteNode,
|
552
|
+
Prism::LocalVariableOperatorWriteNode, Prism::LocalVariableOrWriteNode, Prism::LocalVariableReadNode,
|
553
|
+
Prism::LocalVariableTargetNode, Prism::LocalVariableWriteNode, Prism::DefNode, Prism::BlockParameterNode,
|
554
|
+
Prism::KeywordParameterNode, Prism::KeywordRestParameterNode, Prism::OptionalParameterNode,
|
555
|
+
Prism::RequiredParameterNode, Prism::RestParameterNode
|
556
|
+
|
557
|
+
node.name.to_s
|
558
|
+
when Prism::CallNode
|
559
|
+
node.message
|
560
|
+
when Prism::ClassNode, Prism::ModuleNode
|
561
|
+
node.constant_path.slice
|
562
|
+
end
|
86
563
|
end
|
87
564
|
end
|
88
565
|
end
|
@@ -78,13 +78,13 @@ module RubyLsp
|
|
78
78
|
sig do
|
79
79
|
params(
|
80
80
|
uri: URI::Generic,
|
81
|
-
comments: T::Array[
|
82
|
-
|
81
|
+
comments: T::Array[Prism::Comment],
|
82
|
+
dispatcher: Prism::Dispatcher,
|
83
83
|
message_queue: Thread::Queue,
|
84
84
|
).void
|
85
85
|
end
|
86
|
-
def initialize(uri, comments,
|
87
|
-
super(
|
86
|
+
def initialize(uri, comments, dispatcher, message_queue)
|
87
|
+
super(dispatcher, message_queue)
|
88
88
|
|
89
89
|
# Match the version based on the version in the RBI file name. Notice that the `@` symbol is sanitized to `%40`
|
90
90
|
# in the URI
|
@@ -96,40 +96,47 @@ module RubyLsp
|
|
96
96
|
comments.to_h do |comment|
|
97
97
|
[comment.location.end_line, comment]
|
98
98
|
end,
|
99
|
-
T::Hash[Integer,
|
99
|
+
T::Hash[Integer, Prism::Comment],
|
100
100
|
)
|
101
101
|
|
102
|
-
|
102
|
+
dispatcher.register(
|
103
|
+
self,
|
104
|
+
:on_def_node_enter,
|
105
|
+
:on_class_node_enter,
|
106
|
+
:on_module_node_enter,
|
107
|
+
:on_constant_write_node_enter,
|
108
|
+
:on_constant_path_write_node_enter,
|
109
|
+
)
|
103
110
|
end
|
104
111
|
|
105
|
-
sig { params(node:
|
106
|
-
def
|
112
|
+
sig { params(node: Prism::DefNode).void }
|
113
|
+
def on_def_node_enter(node)
|
107
114
|
extract_document_link(node)
|
108
115
|
end
|
109
116
|
|
110
|
-
sig { params(node:
|
111
|
-
def
|
117
|
+
sig { params(node: Prism::ClassNode).void }
|
118
|
+
def on_class_node_enter(node)
|
112
119
|
extract_document_link(node)
|
113
120
|
end
|
114
121
|
|
115
|
-
sig { params(node:
|
116
|
-
def
|
122
|
+
sig { params(node: Prism::ModuleNode).void }
|
123
|
+
def on_module_node_enter(node)
|
117
124
|
extract_document_link(node)
|
118
125
|
end
|
119
126
|
|
120
|
-
sig { params(node:
|
121
|
-
def
|
127
|
+
sig { params(node: Prism::ConstantWriteNode).void }
|
128
|
+
def on_constant_write_node_enter(node)
|
122
129
|
extract_document_link(node)
|
123
130
|
end
|
124
131
|
|
125
|
-
sig { params(node:
|
126
|
-
def
|
132
|
+
sig { params(node: Prism::ConstantPathWriteNode).void }
|
133
|
+
def on_constant_path_write_node_enter(node)
|
127
134
|
extract_document_link(node)
|
128
135
|
end
|
129
136
|
|
130
137
|
private
|
131
138
|
|
132
|
-
sig { params(node:
|
139
|
+
sig { params(node: Prism::Node).void }
|
133
140
|
def extract_document_link(node)
|
134
141
|
comment = @lines_to_comments[node.location.start_line - 1]
|
135
142
|
return unless comment
|