ruby-lsp 0.11.1 → 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 +28 -108
- data/lib/ruby_indexer/lib/ruby_indexer/prefix_tree.rb +6 -6
- data/lib/ruby_indexer/lib/ruby_indexer/visitor.rb +160 -64
- 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 +111 -30
- data/lib/ruby_indexer/test/index_test.rb +15 -0
- 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 +8 -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 +84 -82
- 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/dependency_detector.rb +12 -4
- data/lib/ruby_lsp/requests/support/rubocop_diagnostic.rb +15 -6
- 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
@@ -32,7 +32,7 @@ module RubyLsp
|
|
32
32
|
|
33
33
|
ResponseType = type_member { { fixed: T::Array[Interface::DocumentSymbol] } }
|
34
34
|
|
35
|
-
ATTR_ACCESSORS = T.let([
|
35
|
+
ATTR_ACCESSORS = T.let([:attr_reader, :attr_writer, :attr_accessor].freeze, T::Array[Symbol])
|
36
36
|
|
37
37
|
class SymbolHierarchyRoot
|
38
38
|
extend T::Sig
|
@@ -49,8 +49,8 @@ module RubyLsp
|
|
49
49
|
sig { override.returns(T::Array[Interface::DocumentSymbol]) }
|
50
50
|
attr_reader :_response
|
51
51
|
|
52
|
-
sig { params(
|
53
|
-
def initialize(
|
52
|
+
sig { params(dispatcher: Prism::Dispatcher, message_queue: Thread::Queue).void }
|
53
|
+
def initialize(dispatcher, message_queue)
|
54
54
|
@root = T.let(SymbolHierarchyRoot.new, SymbolHierarchyRoot)
|
55
55
|
@_response = T.let(@root.children, T::Array[Interface::DocumentSymbol])
|
56
56
|
@stack = T.let(
|
@@ -60,25 +60,25 @@ module RubyLsp
|
|
60
60
|
|
61
61
|
super
|
62
62
|
|
63
|
-
|
63
|
+
dispatcher.register(
|
64
64
|
self,
|
65
|
-
:
|
66
|
-
:
|
67
|
-
:
|
68
|
-
:
|
69
|
-
:
|
70
|
-
:
|
71
|
-
:
|
72
|
-
:
|
73
|
-
:
|
74
|
-
:
|
75
|
-
:
|
65
|
+
:on_class_node_enter,
|
66
|
+
:on_class_node_leave,
|
67
|
+
:on_call_node_enter,
|
68
|
+
:on_constant_path_write_node_enter,
|
69
|
+
:on_constant_write_node_enter,
|
70
|
+
:on_def_node_enter,
|
71
|
+
:on_def_node_leave,
|
72
|
+
:on_module_node_enter,
|
73
|
+
:on_module_node_leave,
|
74
|
+
:on_instance_variable_write_node_enter,
|
75
|
+
:on_class_variable_write_node_enter,
|
76
76
|
)
|
77
77
|
end
|
78
78
|
|
79
79
|
sig { override.params(addon: Addon).returns(T.nilable(Listener[ResponseType])) }
|
80
80
|
def initialize_external_listener(addon)
|
81
|
-
addon.create_document_symbol_listener(@
|
81
|
+
addon.create_document_symbol_listener(@dispatcher, @message_queue)
|
82
82
|
end
|
83
83
|
|
84
84
|
# Merges responses from other listeners
|
@@ -88,8 +88,8 @@ module RubyLsp
|
|
88
88
|
self
|
89
89
|
end
|
90
90
|
|
91
|
-
sig { params(node:
|
92
|
-
def
|
91
|
+
sig { params(node: Prism::ClassNode).void }
|
92
|
+
def on_class_node_enter(node)
|
93
93
|
@stack << create_document_symbol(
|
94
94
|
name: node.constant_path.location.slice,
|
95
95
|
kind: Constant::SymbolKind::CLASS,
|
@@ -98,20 +98,20 @@ module RubyLsp
|
|
98
98
|
)
|
99
99
|
end
|
100
100
|
|
101
|
-
sig { params(node:
|
102
|
-
def
|
101
|
+
sig { params(node: Prism::ClassNode).void }
|
102
|
+
def on_class_node_leave(node)
|
103
103
|
@stack.pop
|
104
104
|
end
|
105
105
|
|
106
|
-
sig { params(node:
|
107
|
-
def
|
106
|
+
sig { params(node: Prism::CallNode).void }
|
107
|
+
def on_call_node_enter(node)
|
108
108
|
return unless ATTR_ACCESSORS.include?(node.name) && node.receiver.nil?
|
109
109
|
|
110
110
|
arguments = node.arguments
|
111
111
|
return unless arguments
|
112
112
|
|
113
113
|
arguments.arguments.each do |argument|
|
114
|
-
next unless argument.is_a?(
|
114
|
+
next unless argument.is_a?(Prism::SymbolNode)
|
115
115
|
|
116
116
|
name = argument.value
|
117
117
|
next unless name
|
@@ -125,8 +125,8 @@ module RubyLsp
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
-
sig { params(node:
|
129
|
-
def
|
128
|
+
sig { params(node: Prism::ConstantPathWriteNode).void }
|
129
|
+
def on_constant_path_write_node_enter(node)
|
130
130
|
create_document_symbol(
|
131
131
|
name: node.target.location.slice,
|
132
132
|
kind: Constant::SymbolKind::CONSTANT,
|
@@ -135,8 +135,8 @@ module RubyLsp
|
|
135
135
|
)
|
136
136
|
end
|
137
137
|
|
138
|
-
sig { params(node:
|
139
|
-
def
|
138
|
+
sig { params(node: Prism::ConstantWriteNode).void }
|
139
|
+
def on_constant_write_node_enter(node)
|
140
140
|
create_document_symbol(
|
141
141
|
name: node.name.to_s,
|
142
142
|
kind: Constant::SymbolKind::CONSTANT,
|
@@ -145,13 +145,13 @@ module RubyLsp
|
|
145
145
|
)
|
146
146
|
end
|
147
147
|
|
148
|
-
sig { params(node:
|
149
|
-
def
|
148
|
+
sig { params(node: Prism::DefNode).void }
|
149
|
+
def on_def_node_leave(node)
|
150
150
|
@stack.pop
|
151
151
|
end
|
152
152
|
|
153
|
-
sig { params(node:
|
154
|
-
def
|
153
|
+
sig { params(node: Prism::ModuleNode).void }
|
154
|
+
def on_module_node_enter(node)
|
155
155
|
@stack << create_document_symbol(
|
156
156
|
name: node.constant_path.location.slice,
|
157
157
|
kind: Constant::SymbolKind::MODULE,
|
@@ -160,11 +160,11 @@ module RubyLsp
|
|
160
160
|
)
|
161
161
|
end
|
162
162
|
|
163
|
-
sig { params(node:
|
164
|
-
def
|
163
|
+
sig { params(node: Prism::DefNode).void }
|
164
|
+
def on_def_node_enter(node)
|
165
165
|
receiver = node.receiver
|
166
166
|
|
167
|
-
if receiver.is_a?(
|
167
|
+
if receiver.is_a?(Prism::SelfNode)
|
168
168
|
name = "self.#{node.name}"
|
169
169
|
kind = Constant::SymbolKind::METHOD
|
170
170
|
else
|
@@ -182,13 +182,13 @@ module RubyLsp
|
|
182
182
|
@stack << symbol
|
183
183
|
end
|
184
184
|
|
185
|
-
sig { params(node:
|
186
|
-
def
|
185
|
+
sig { params(node: Prism::ModuleNode).void }
|
186
|
+
def on_module_node_leave(node)
|
187
187
|
@stack.pop
|
188
188
|
end
|
189
189
|
|
190
|
-
sig { params(node:
|
191
|
-
def
|
190
|
+
sig { params(node: Prism::InstanceVariableWriteNode).void }
|
191
|
+
def on_instance_variable_write_node_enter(node)
|
192
192
|
create_document_symbol(
|
193
193
|
name: node.name.to_s,
|
194
194
|
kind: Constant::SymbolKind::VARIABLE,
|
@@ -197,8 +197,8 @@ module RubyLsp
|
|
197
197
|
)
|
198
198
|
end
|
199
199
|
|
200
|
-
sig { params(node:
|
201
|
-
def
|
200
|
+
sig { params(node: Prism::ClassVariableWriteNode).void }
|
201
|
+
def on_class_variable_write_node_enter(node)
|
202
202
|
create_document_symbol(
|
203
203
|
name: node.name.to_s,
|
204
204
|
kind: Constant::SymbolKind::VARIABLE,
|
@@ -213,8 +213,8 @@ module RubyLsp
|
|
213
213
|
params(
|
214
214
|
name: String,
|
215
215
|
kind: Integer,
|
216
|
-
range_location:
|
217
|
-
selection_range_location:
|
216
|
+
range_location: Prism::Location,
|
217
|
+
selection_range_location: Prism::Location,
|
218
218
|
).returns(Interface::DocumentSymbol)
|
219
219
|
end
|
220
220
|
def create_document_symbol(name:, kind:, range_location:, selection_range_location:)
|
@@ -21,39 +21,40 @@ module RubyLsp
|
|
21
21
|
|
22
22
|
ResponseType = type_member { { fixed: T::Array[Interface::FoldingRange] } }
|
23
23
|
|
24
|
-
sig { params(comments: T::Array[
|
25
|
-
def initialize(comments,
|
26
|
-
super(
|
24
|
+
sig { params(comments: T::Array[Prism::Comment], dispatcher: Prism::Dispatcher, queue: Thread::Queue).void }
|
25
|
+
def initialize(comments, dispatcher, queue)
|
26
|
+
super(dispatcher, queue)
|
27
27
|
|
28
28
|
@_response = T.let([], ResponseType)
|
29
|
-
@requires = T.let([], T::Array[
|
29
|
+
@requires = T.let([], T::Array[Prism::CallNode])
|
30
30
|
@finalized_response = T.let(false, T::Boolean)
|
31
31
|
@comments = comments
|
32
32
|
|
33
|
-
|
33
|
+
dispatcher.register(
|
34
34
|
self,
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
40
|
-
:
|
41
|
-
:
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
56
|
-
:
|
35
|
+
:on_if_node_enter,
|
36
|
+
:on_in_node_enter,
|
37
|
+
:on_rescue_node_enter,
|
38
|
+
:on_when_node_enter,
|
39
|
+
:on_interpolated_string_node_enter,
|
40
|
+
:on_array_node_enter,
|
41
|
+
:on_block_node_enter,
|
42
|
+
:on_case_node_enter,
|
43
|
+
:on_class_node_enter,
|
44
|
+
:on_module_node_enter,
|
45
|
+
:on_for_node_enter,
|
46
|
+
:on_hash_node_enter,
|
47
|
+
:on_singleton_class_node_enter,
|
48
|
+
:on_unless_node_enter,
|
49
|
+
:on_until_node_enter,
|
50
|
+
:on_while_node_enter,
|
51
|
+
:on_else_node_enter,
|
52
|
+
:on_ensure_node_enter,
|
53
|
+
:on_begin_node_enter,
|
54
|
+
:on_string_concat_node_enter,
|
55
|
+
:on_def_node_enter,
|
56
|
+
:on_call_node_enter,
|
57
|
+
:on_lambda_node_enter,
|
57
58
|
)
|
58
59
|
end
|
59
60
|
|
@@ -68,119 +69,114 @@ module RubyLsp
|
|
68
69
|
@_response
|
69
70
|
end
|
70
71
|
|
71
|
-
sig { params(node:
|
72
|
-
def
|
72
|
+
sig { params(node: Prism::IfNode).void }
|
73
|
+
def on_if_node_enter(node)
|
73
74
|
add_statements_range(node)
|
74
75
|
end
|
75
76
|
|
76
|
-
sig { params(node:
|
77
|
-
def
|
77
|
+
sig { params(node: Prism::InNode).void }
|
78
|
+
def on_in_node_enter(node)
|
78
79
|
add_statements_range(node)
|
79
80
|
end
|
80
81
|
|
81
|
-
sig { params(node:
|
82
|
-
def
|
82
|
+
sig { params(node: Prism::RescueNode).void }
|
83
|
+
def on_rescue_node_enter(node)
|
83
84
|
add_statements_range(node)
|
84
85
|
end
|
85
86
|
|
86
|
-
sig { params(node:
|
87
|
-
def
|
87
|
+
sig { params(node: Prism::WhenNode).void }
|
88
|
+
def on_when_node_enter(node)
|
88
89
|
add_statements_range(node)
|
89
90
|
end
|
90
91
|
|
91
|
-
sig { params(node:
|
92
|
-
def
|
92
|
+
sig { params(node: Prism::InterpolatedStringNode).void }
|
93
|
+
def on_interpolated_string_node_enter(node)
|
93
94
|
opening_loc = node.opening_loc
|
94
95
|
closing_loc = node.closing_loc
|
95
96
|
|
96
97
|
add_lines_range(opening_loc.start_line, closing_loc.end_line - 1) if opening_loc && closing_loc
|
97
98
|
end
|
98
99
|
|
99
|
-
sig { params(node:
|
100
|
-
def
|
100
|
+
sig { params(node: Prism::ArrayNode).void }
|
101
|
+
def on_array_node_enter(node)
|
101
102
|
add_simple_range(node)
|
102
103
|
end
|
103
104
|
|
104
|
-
sig { params(node:
|
105
|
-
def
|
105
|
+
sig { params(node: Prism::BlockNode).void }
|
106
|
+
def on_block_node_enter(node)
|
106
107
|
add_simple_range(node)
|
107
108
|
end
|
108
109
|
|
109
|
-
sig { params(node:
|
110
|
-
def
|
110
|
+
sig { params(node: Prism::CaseNode).void }
|
111
|
+
def on_case_node_enter(node)
|
111
112
|
add_simple_range(node)
|
112
113
|
end
|
113
114
|
|
114
|
-
sig { params(node:
|
115
|
-
def
|
115
|
+
sig { params(node: Prism::ClassNode).void }
|
116
|
+
def on_class_node_enter(node)
|
116
117
|
add_simple_range(node)
|
117
118
|
end
|
118
119
|
|
119
|
-
sig { params(node:
|
120
|
-
def
|
120
|
+
sig { params(node: Prism::ModuleNode).void }
|
121
|
+
def on_module_node_enter(node)
|
121
122
|
add_simple_range(node)
|
122
123
|
end
|
123
124
|
|
124
|
-
sig { params(node:
|
125
|
-
def
|
125
|
+
sig { params(node: Prism::ForNode).void }
|
126
|
+
def on_for_node_enter(node)
|
126
127
|
add_simple_range(node)
|
127
128
|
end
|
128
129
|
|
129
|
-
sig { params(node:
|
130
|
-
def
|
130
|
+
sig { params(node: Prism::HashNode).void }
|
131
|
+
def on_hash_node_enter(node)
|
131
132
|
add_simple_range(node)
|
132
133
|
end
|
133
134
|
|
134
|
-
sig { params(node:
|
135
|
-
def
|
135
|
+
sig { params(node: Prism::SingletonClassNode).void }
|
136
|
+
def on_singleton_class_node_enter(node)
|
136
137
|
add_simple_range(node)
|
137
138
|
end
|
138
139
|
|
139
|
-
sig { params(node:
|
140
|
-
def
|
140
|
+
sig { params(node: Prism::UnlessNode).void }
|
141
|
+
def on_unless_node_enter(node)
|
141
142
|
add_simple_range(node)
|
142
143
|
end
|
143
144
|
|
144
|
-
sig { params(node:
|
145
|
-
def
|
145
|
+
sig { params(node: Prism::UntilNode).void }
|
146
|
+
def on_until_node_enter(node)
|
146
147
|
add_simple_range(node)
|
147
148
|
end
|
148
149
|
|
149
|
-
sig { params(node:
|
150
|
-
def
|
150
|
+
sig { params(node: Prism::WhileNode).void }
|
151
|
+
def on_while_node_enter(node)
|
151
152
|
add_simple_range(node)
|
152
153
|
end
|
153
154
|
|
154
|
-
sig { params(node:
|
155
|
-
def
|
155
|
+
sig { params(node: Prism::ElseNode).void }
|
156
|
+
def on_else_node_enter(node)
|
156
157
|
add_simple_range(node)
|
157
158
|
end
|
158
159
|
|
159
|
-
sig { params(node:
|
160
|
-
def
|
160
|
+
sig { params(node: Prism::EnsureNode).void }
|
161
|
+
def on_ensure_node_enter(node)
|
161
162
|
add_simple_range(node)
|
162
163
|
end
|
163
164
|
|
164
|
-
sig { params(node:
|
165
|
-
def
|
165
|
+
sig { params(node: Prism::BeginNode).void }
|
166
|
+
def on_begin_node_enter(node)
|
166
167
|
add_simple_range(node)
|
167
168
|
end
|
168
169
|
|
169
|
-
sig { params(node:
|
170
|
-
def
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
sig { params(node: YARP::StringConcatNode).void }
|
175
|
-
def on_string_concat(node)
|
176
|
-
left = T.let(node.left, YARP::Node)
|
177
|
-
left = left.left while left.is_a?(YARP::StringConcatNode)
|
170
|
+
sig { params(node: Prism::StringConcatNode).void }
|
171
|
+
def on_string_concat_node_enter(node)
|
172
|
+
left = T.let(node.left, Prism::Node)
|
173
|
+
left = left.left while left.is_a?(Prism::StringConcatNode)
|
178
174
|
|
179
175
|
add_lines_range(left.location.start_line, node.right.location.end_line - 1)
|
180
176
|
end
|
181
177
|
|
182
|
-
sig { params(node:
|
183
|
-
def
|
178
|
+
sig { params(node: Prism::DefNode).void }
|
179
|
+
def on_def_node_enter(node)
|
184
180
|
params = node.parameters
|
185
181
|
parameter_loc = params&.location
|
186
182
|
location = node.location
|
@@ -194,8 +190,8 @@ module RubyLsp
|
|
194
190
|
end
|
195
191
|
end
|
196
192
|
|
197
|
-
sig { params(node:
|
198
|
-
def
|
193
|
+
sig { params(node: Prism::CallNode).void }
|
194
|
+
def on_call_node_enter(node)
|
199
195
|
# If we find a require, don't visit the child nodes (prevent `super`), so that we can keep accumulating into
|
200
196
|
# the `@requires` array and then push the range whenever we find a node that isn't a CallNode
|
201
197
|
if require?(node)
|
@@ -207,6 +203,11 @@ module RubyLsp
|
|
207
203
|
add_lines_range(location.start_line, location.end_line - 1)
|
208
204
|
end
|
209
205
|
|
206
|
+
sig { params(node: Prism::LambdaNode).void }
|
207
|
+
def on_lambda_node_enter(node)
|
208
|
+
add_simple_range(node)
|
209
|
+
end
|
210
|
+
|
210
211
|
private
|
211
212
|
|
212
213
|
sig { void }
|
@@ -238,7 +239,7 @@ module RubyLsp
|
|
238
239
|
@requires.clear
|
239
240
|
end
|
240
241
|
|
241
|
-
sig { params(node:
|
242
|
+
sig { params(node: Prism::CallNode).returns(T::Boolean) }
|
242
243
|
def require?(node)
|
243
244
|
message = node.message
|
244
245
|
return false unless message == "require" || message == "require_relative"
|
@@ -249,10 +250,10 @@ module RubyLsp
|
|
249
250
|
arguments = node.arguments&.arguments
|
250
251
|
return false unless arguments
|
251
252
|
|
252
|
-
arguments.length == 1 && arguments.first.is_a?(
|
253
|
+
arguments.length == 1 && arguments.first.is_a?(Prism::StringNode)
|
253
254
|
end
|
254
255
|
|
255
|
-
sig { params(node: T.any(
|
256
|
+
sig { params(node: T.any(Prism::IfNode, Prism::InNode, Prism::RescueNode, Prism::WhenNode)).void }
|
256
257
|
def add_statements_range(node)
|
257
258
|
statements = node.statements
|
258
259
|
return unless statements
|
@@ -263,7 +264,7 @@ module RubyLsp
|
|
263
264
|
add_lines_range(node.location.start_line, T.must(body.last).location.end_line)
|
264
265
|
end
|
265
266
|
|
266
|
-
sig { params(node:
|
267
|
+
sig { params(node: Prism::Node).void }
|
267
268
|
def add_simple_range(node)
|
268
269
|
location = node.location
|
269
270
|
add_lines_range(location.start_line, location.end_line - 1)
|
@@ -271,6 +272,7 @@ module RubyLsp
|
|
271
272
|
|
272
273
|
sig { params(start_line: Integer, end_line: Integer).void }
|
273
274
|
def add_lines_range(start_line, end_line)
|
275
|
+
emit_requires_range
|
274
276
|
return if start_line >= end_line
|
275
277
|
|
276
278
|
@_response << Interface::FoldingRange.new(
|
@@ -21,12 +21,12 @@ module RubyLsp
|
|
21
21
|
|
22
22
|
ALLOWED_TARGETS = T.let(
|
23
23
|
[
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
Prism::CallNode,
|
25
|
+
Prism::ConstantReadNode,
|
26
|
+
Prism::ConstantWriteNode,
|
27
|
+
Prism::ConstantPathNode,
|
28
28
|
],
|
29
|
-
T::Array[T.class_of(
|
29
|
+
T::Array[T.class_of(Prism::Node)],
|
30
30
|
)
|
31
31
|
|
32
32
|
sig { override.returns(ResponseType) }
|
@@ -36,22 +36,27 @@ module RubyLsp
|
|
36
36
|
params(
|
37
37
|
index: RubyIndexer::Index,
|
38
38
|
nesting: T::Array[String],
|
39
|
-
|
39
|
+
dispatcher: Prism::Dispatcher,
|
40
40
|
message_queue: Thread::Queue,
|
41
41
|
).void
|
42
42
|
end
|
43
|
-
def initialize(index, nesting,
|
43
|
+
def initialize(index, nesting, dispatcher, message_queue)
|
44
44
|
@index = index
|
45
45
|
@nesting = nesting
|
46
46
|
@_response = T.let(nil, ResponseType)
|
47
47
|
|
48
|
-
super(
|
49
|
-
|
48
|
+
super(dispatcher, message_queue)
|
49
|
+
dispatcher.register(
|
50
|
+
self,
|
51
|
+
:on_constant_read_node_enter,
|
52
|
+
:on_constant_write_node_enter,
|
53
|
+
:on_constant_path_node_enter,
|
54
|
+
)
|
50
55
|
end
|
51
56
|
|
52
57
|
sig { override.params(addon: Addon).returns(T.nilable(Listener[ResponseType])) }
|
53
58
|
def initialize_external_listener(addon)
|
54
|
-
addon.create_hover_listener(@nesting, @index, @
|
59
|
+
addon.create_hover_listener(@nesting, @index, @dispatcher, @message_queue)
|
55
60
|
end
|
56
61
|
|
57
62
|
# Merges responses from other hover listeners
|
@@ -69,22 +74,22 @@ module RubyLsp
|
|
69
74
|
self
|
70
75
|
end
|
71
76
|
|
72
|
-
sig { params(node:
|
73
|
-
def
|
77
|
+
sig { params(node: Prism::ConstantReadNode).void }
|
78
|
+
def on_constant_read_node_enter(node)
|
74
79
|
return if DependencyDetector.instance.typechecker
|
75
80
|
|
76
81
|
generate_hover(node.slice, node.location)
|
77
82
|
end
|
78
83
|
|
79
|
-
sig { params(node:
|
80
|
-
def
|
84
|
+
sig { params(node: Prism::ConstantWriteNode).void }
|
85
|
+
def on_constant_write_node_enter(node)
|
81
86
|
return if DependencyDetector.instance.typechecker
|
82
87
|
|
83
88
|
generate_hover(node.name.to_s, node.name_loc)
|
84
89
|
end
|
85
90
|
|
86
|
-
sig { params(node:
|
87
|
-
def
|
91
|
+
sig { params(node: Prism::ConstantPathNode).void }
|
92
|
+
def on_constant_path_node_enter(node)
|
88
93
|
return if DependencyDetector.instance.typechecker
|
89
94
|
|
90
95
|
generate_hover(node.slice, node.location)
|
@@ -92,7 +97,7 @@ module RubyLsp
|
|
92
97
|
|
93
98
|
private
|
94
99
|
|
95
|
-
sig { params(name: String, location:
|
100
|
+
sig { params(name: String, location: Prism::Location).void }
|
96
101
|
def generate_hover(name, location)
|
97
102
|
entries = @index.resolve(name, @nesting)
|
98
103
|
return unless entries
|
@@ -29,18 +29,18 @@ module RubyLsp
|
|
29
29
|
sig { override.returns(ResponseType) }
|
30
30
|
attr_reader :_response
|
31
31
|
|
32
|
-
sig { params(range: T::Range[Integer],
|
33
|
-
def initialize(range,
|
34
|
-
super(
|
32
|
+
sig { params(range: T::Range[Integer], dispatcher: Prism::Dispatcher, message_queue: Thread::Queue).void }
|
33
|
+
def initialize(range, dispatcher, message_queue)
|
34
|
+
super(dispatcher, message_queue)
|
35
35
|
|
36
36
|
@_response = T.let([], ResponseType)
|
37
37
|
@range = range
|
38
38
|
|
39
|
-
|
39
|
+
dispatcher.register(self, :on_rescue_node_enter)
|
40
40
|
end
|
41
41
|
|
42
|
-
sig { params(node:
|
43
|
-
def
|
42
|
+
sig { params(node: Prism::RescueNode).void }
|
43
|
+
def on_rescue_node_enter(node)
|
44
44
|
return unless node.exceptions.empty?
|
45
45
|
|
46
46
|
loc = node.location
|