@@ -12,6 +12,61 @@ class DocumentSymbol
12
12
include Requests ::Support ::Common
13
13
include ActiveSupportTestCaseHelper
14
14
15
+ MODEL_CALLBACKS = T . let (
16
+ [
17
+ "before_validation" ,
18
+ "after_validation" ,
19
+ "before_save" ,
20
+ "around_save" ,
21
+ "before_create" ,
22
+ "around_create" ,
23
+ "after_create" ,
24
+ "after_save" ,
25
+ "after_commit" ,
26
+ "after_rollback" ,
27
+ "before_update" ,
28
+ "around_update" ,
29
+ "after_update" ,
30
+ "before_destroy" ,
31
+ "around_destroy" ,
32
+ "after_destroy" ,
33
+ "after_initialize" ,
34
+ "after_find" ,
35
+ "after_touch" ,
36
+ ] . freeze ,
37
+ T ::Array [ String ] ,
38
+ )
39
+
40
+ CONTROLLER_CALLBACKS = T . let (
41
+ [
42
+ "after_action" ,
43
+ "append_after_action" ,
44
+ "append_around_action" ,
45
+ "append_before_action" ,
46
+ "around_action" ,
47
+ "before_action" ,
48
+ "prepend_after_action" ,
49
+ "prepend_around_action" ,
50
+ "prepend_before_action" ,
51
+ "skip_after_action" ,
52
+ "skip_around_action" ,
53
+ "skip_before_action" ,
54
+ ] . freeze ,
55
+ T ::Array [ String ] ,
56
+ )
57
+
58
+ JOB_CALLBACKS = T . let (
59
+ [
60
+ "after_enqueue" ,
61
+ "after_perform" ,
62
+ "around_enqueue" ,
63
+ "around_perform" ,
64
+ "before_enqueue" ,
65
+ "before_perform" ,
66
+ ] . freeze ,
67
+ T ::Array [ String ] ,
68
+ )
69
+
15
70
sig do
16
71
params (
17
72
response_builder : ResponseBuilders ::DocumentSymbol ,
@@ -28,13 +83,79 @@ def initialize(response_builder, dispatcher)
28
83
def on_call_node_enter ( node )
29
84
content = extract_test_case_name ( node )
30
85
31
- return unless content
86
+ if content
87
+ append_document_symbol (
88
+ name : content ,
89
+ selection_range : range_from_node ( node ) ,
90
+ range : range_from_node ( node ) ,
91
+ )
92
+ end
93
+
94
+ extract_callbacks ( node )
95
+ end
96
+
97
+ private
98
+
99
+ sig { params ( node : Prism ::CallNode ) . void }
100
+ def extract_callbacks ( node )
101
+ receiver = node . receiver
102
+ return if receiver && !receiver . is_a? ( Prism ::SelfNode )
103
+
104
+ message_value = node . message
105
+ callbacks = [ MODEL_CALLBACKS , CONTROLLER_CALLBACKS , JOB_CALLBACKS ]
106
+
107
+ return unless callbacks . any? { |callback | callback . include? ( message_value ) }
108
+
109
+ block = node . block
32
110
111
+ if block
112
+ append_document_symbol (
113
+ name : "#{ message_value } (<anonymous>)" ,
114
+ range : range_from_location ( node . location ) ,
115
+ selection_range : range_from_location ( block . location ) ,
116
+ )
117
+ return
118
+ end
119
+
120
+ arguments = node . arguments &.arguments
121
+ return unless arguments &.any?
122
+
123
+ arguments . each do |argument |
124
+ if argument . is_a? ( Prism ::SymbolNode )
125
+ name = argument . value
126
+ next unless name
127
+
128
+ append_document_symbol (
129
+ name : "#{ message_value } (#{ name } )" ,
130
+ range : range_from_location ( argument . location ) ,
131
+ selection_range : range_from_location ( T . must ( argument . value_loc ) ) ,
132
+ )
133
+ elsif argument . is_a? ( Prism ::StringNode )
134
+ name = argument . content
135
+ next if name . empty?
136
+
137
+ append_document_symbol (
138
+ name : "#{ message_value } (#{ name } )" ,
139
+ range : range_from_location ( argument . location ) ,
140
+ selection_range : range_from_location ( argument . content_loc ) ,
141
+ )
142
+ end
143
+ end
144
+ end
145
+
146
+ sig do
147
+ params (
148
+ name : String ,
149
+ range : RubyLsp ::Interface ::Range ,
150
+ selection_range : RubyLsp ::Interface ::Range ,
151
+ ) . void
152
+ end
153
+ def append_document_symbol ( name :, range :, selection_range :)
33
154
@response_builder . last . children << RubyLsp ::Interface ::DocumentSymbol . new (
34
- name : content ,
35
- kind : LanguageServer :: Protocol ::Constant ::SymbolKind ::METHOD ,
36
- selection_range : range_from_node ( node ) ,
37
- range : range_from_node ( node ) ,
155
+ name : name ,
156
+ kind : RubyLsp ::Constant ::SymbolKind ::METHOD ,
157
+ range : range ,
158
+ selection_range : selection_range ,
38
159
)
39
160
end
40
161
end
0 commit comments