@@ -93,25 +93,29 @@ def on_call_node_enter(node)
93
93
)
94
94
end
95
95
96
- extract_callbacks ( node )
97
- end
98
-
99
- private
100
-
101
- sig { params ( node : Prism ::CallNode ) . void }
102
- def extract_callbacks ( node )
103
96
receiver = node . receiver
104
97
return if receiver && !receiver . is_a? ( Prism ::SelfNode )
105
98
106
- message_value = node . message
99
+ message = node . message
100
+ case message
101
+ when *CALLBACKS , "validate"
102
+ handle_all_arg_types ( node , T . must ( message ) )
103
+ when "validates" , "validates!" , "validates_each"
104
+ handle_symbol_and_string_arg_types ( node , T . must ( message ) )
105
+ when "validates_with"
106
+ handle_class_arg_types ( node , T . must ( message ) )
107
+ end
108
+ end
107
109
108
- return unless CALLBACKS . include? ( message_value )
110
+ private
109
111
112
+ sig { params ( node : Prism ::CallNode , message : String ) . void }
113
+ def handle_all_arg_types ( node , message )
110
114
block = node . block
111
115
112
116
if block
113
117
append_document_symbol (
114
- name : "#{ message_value } (<anonymous>)" ,
118
+ name : "#{ message } (<anonymous>)" ,
115
119
range : range_from_location ( node . location ) ,
116
120
selection_range : range_from_location ( block . location ) ,
117
121
)
@@ -128,7 +132,7 @@ def extract_callbacks(node)
128
132
next unless name
129
133
130
134
append_document_symbol (
131
- name : "#{ message_value } (#{ name } )" ,
135
+ name : "#{ message } (#{ name } )" ,
132
136
range : range_from_location ( argument . location ) ,
133
137
selection_range : range_from_location ( T . must ( argument . value_loc ) ) ,
134
138
)
@@ -137,13 +141,13 @@ def extract_callbacks(node)
137
141
next if name . empty?
138
142
139
143
append_document_symbol (
140
- name : "#{ message_value } (#{ name } )" ,
144
+ name : "#{ message } (#{ name } )" ,
141
145
range : range_from_location ( argument . location ) ,
142
146
selection_range : range_from_location ( argument . content_loc ) ,
143
147
)
144
148
when Prism ::LambdaNode
145
149
append_document_symbol (
146
- name : "#{ message_value } (<anonymous>)" ,
150
+ name : "#{ message } (<anonymous>)" ,
147
151
range : range_from_location ( node . location ) ,
148
152
selection_range : range_from_location ( argument . location ) ,
149
153
)
@@ -157,7 +161,7 @@ def extract_callbacks(node)
157
161
next unless name
158
162
159
163
append_document_symbol (
160
- name : "#{ message_value } (#{ name } )" ,
164
+ name : "#{ message } (#{ name } )" ,
161
165
range : range_from_location ( argument . location ) ,
162
166
selection_range : range_from_location ( argument . location ) ,
163
167
)
@@ -166,7 +170,65 @@ def extract_callbacks(node)
166
170
next if name . empty?
167
171
168
172
append_document_symbol (
169
- name : "#{ message_value } (#{ name } )" ,
173
+ name : "#{ message } (#{ name } )" ,
174
+ range : range_from_location ( argument . location ) ,
175
+ selection_range : range_from_location ( argument . location ) ,
176
+ )
177
+ when Prism ::ConstantPathNode
178
+ name = argument . full_name
179
+ next if name . empty?
180
+
181
+ append_document_symbol (
182
+ name : "#{ message } (#{ name } )" ,
183
+ range : range_from_location ( argument . location ) ,
184
+ selection_range : range_from_location ( argument . location ) ,
185
+ )
186
+ end
187
+ end
188
+ end
189
+
190
+ sig { params ( node : Prism ::CallNode , message : String ) . void }
191
+ def handle_symbol_and_string_arg_types ( node , message )
192
+ arguments = node . arguments &.arguments
193
+ return unless arguments &.any?
194
+
195
+ arguments . each do |argument |
196
+ case argument
197
+ when Prism ::SymbolNode
198
+ name = argument . value
199
+ next unless name
200
+
201
+ append_document_symbol (
202
+ name : "#{ message } (#{ name } )" ,
203
+ range : range_from_location ( argument . location ) ,
204
+ selection_range : range_from_location ( T . must ( argument . value_loc ) ) ,
205
+ )
206
+ when Prism ::StringNode
207
+ name = argument . content
208
+ next if name . empty?
209
+
210
+ append_document_symbol (
211
+ name : "#{ message } (#{ name } )" ,
212
+ range : range_from_location ( argument . location ) ,
213
+ selection_range : range_from_location ( argument . content_loc ) ,
214
+ )
215
+ end
216
+ end
217
+ end
218
+
219
+ sig { params ( node : Prism ::CallNode , message : String ) . void }
220
+ def handle_class_arg_types ( node , message )
221
+ arguments = node . arguments &.arguments
222
+ return unless arguments &.any?
223
+
224
+ arguments . each do |argument |
225
+ case argument
226
+ when Prism ::ConstantReadNode
227
+ name = argument . name
228
+ next if name . empty?
229
+
230
+ append_document_symbol (
231
+ name : "#{ message } (#{ name } )" ,
170
232
range : range_from_location ( argument . location ) ,
171
233
selection_range : range_from_location ( argument . location ) ,
172
234
)
@@ -175,7 +237,7 @@ def extract_callbacks(node)
175
237
next if name . empty?
176
238
177
239
append_document_symbol (
178
- name : "#{ message_value } (#{ name } )" ,
240
+ name : "#{ message } (#{ name } )" ,
179
241
range : range_from_location ( argument . location ) ,
180
242
selection_range : range_from_location ( argument . location ) ,
181
243
)
0 commit comments