ruby-lsp 0.13.2 → 0.13.4

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