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