@@ -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,16 +161,65 @@ 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
)
168
+ when Prism ::ConstantReadNode , Prism ::ConstantPathNode
169
+ name = argument . full_name
170
+ next if name . empty?
171
+
172
+ append_document_symbol (
173
+ name : "#{ message } (#{ name } )" ,
174
+ range : range_from_location ( argument . location ) ,
175
+ selection_range : range_from_location ( argument . location ) ,
176
+ )
177
+ end
178
+ end
179
+ end
180
+
181
+ sig { params ( node : Prism ::CallNode , message : String ) . void }
182
+ def handle_symbol_and_string_arg_types ( node , message )
183
+ arguments = node . arguments &.arguments
184
+ return unless arguments &.any?
185
+
186
+ arguments . each do |argument |
187
+ case argument
188
+ when Prism ::SymbolNode
189
+ name = argument . value
190
+ next unless name
191
+
192
+ append_document_symbol (
193
+ name : "#{ message } (#{ name } )" ,
194
+ range : range_from_location ( argument . location ) ,
195
+ selection_range : range_from_location ( T . must ( argument . value_loc ) ) ,
196
+ )
197
+ when Prism ::StringNode
198
+ name = argument . content
199
+ next if name . empty?
200
+
201
+ append_document_symbol (
202
+ name : "#{ message } (#{ name } )" ,
203
+ range : range_from_location ( argument . location ) ,
204
+ selection_range : range_from_location ( argument . content_loc ) ,
205
+ )
206
+ end
207
+ end
208
+ end
209
+
210
+ sig { params ( node : Prism ::CallNode , message : String ) . void }
211
+ def handle_class_arg_types ( node , message )
212
+ arguments = node . arguments &.arguments
213
+ return unless arguments &.any?
214
+
215
+ arguments . each do |argument |
216
+ case argument
164
217
when Prism ::ConstantReadNode
165
218
name = argument . name
166
219
next if name . empty?
167
220
168
221
append_document_symbol (
169
- name : "#{ message_value } (#{ name } )" ,
222
+ name : "#{ message } (#{ name } )" ,
170
223
range : range_from_location ( argument . location ) ,
171
224
selection_range : range_from_location ( argument . location ) ,
172
225
)
@@ -175,7 +228,7 @@ def extract_callbacks(node)
175
228
next if name . empty?
176
229
177
230
append_document_symbol (
178
- name : "#{ message_value } (#{ name } )" ,
231
+ name : "#{ message } (#{ name } )" ,
179
232
range : range_from_location ( argument . location ) ,
180
233
selection_range : range_from_location ( argument . location ) ,
181
234
)
0 commit comments