@@ -8,25 +8,18 @@ class IndexingEnhancement < RubyIndexer::Enhancement
8
8
9
9
sig do
10
10
override . params (
11
- owner : T . nilable ( RubyIndexer ::Entry ::Namespace ) ,
12
- node : Prism ::CallNode ,
13
- file_path : String ,
14
- code_units_cache : T . any (
15
- T . proc . params ( arg0 : Integer ) . returns ( Integer ) ,
16
- Prism ::CodeUnitsCache ,
17
- ) ,
11
+ call_node : Prism ::CallNode ,
18
12
) . void
19
13
end
20
- def on_call_node_enter ( owner , node , file_path , code_units_cache )
14
+ def on_call_node_enter ( call_node )
15
+ owner = @listener . current_owner
21
16
return unless owner
22
17
23
- name = node . name
24
-
25
- case name
18
+ case call_node . name
26
19
when :extend
27
- handle_concern_extend ( owner , node )
20
+ handle_concern_extend ( owner , call_node )
28
21
when :has_one , :has_many , :belongs_to , :has_and_belongs_to_many
29
- handle_association ( owner , node , file_path , code_units_cache )
22
+ handle_association ( owner , call_node )
30
23
end
31
24
end
32
25
@@ -35,16 +28,11 @@ def on_call_node_enter(owner, node, file_path, code_units_cache)
35
28
sig do
36
29
params (
37
30
owner : RubyIndexer ::Entry ::Namespace ,
38
- node : Prism ::CallNode ,
39
- file_path : String ,
40
- code_units_cache : T . any (
41
- T . proc . params ( arg0 : Integer ) . returns ( Integer ) ,
42
- Prism ::CodeUnitsCache ,
43
- ) ,
31
+ call_node : Prism ::CallNode ,
44
32
) . void
45
33
end
46
- def handle_association ( owner , node , file_path , code_units_cache )
47
- arguments = node . arguments &.arguments
34
+ def handle_association ( owner , call_node )
35
+ arguments = call_node . arguments &.arguments
48
36
return unless arguments
49
37
50
38
name_arg = arguments . first
@@ -58,41 +46,22 @@ def handle_association(owner, node, file_path, code_units_cache)
58
46
59
47
return unless name
60
48
61
- loc = RubyIndexer :: Location . from_prism_location ( name_arg . location , code_units_cache )
49
+ loc = name_arg . location
62
50
63
51
# Reader
64
- @index . add ( RubyIndexer ::Entry ::Method . new (
65
- name ,
66
- file_path ,
67
- loc ,
68
- loc ,
69
- nil ,
70
- [ RubyIndexer ::Entry ::Signature . new ( [ ] ) ] ,
71
- RubyIndexer ::Entry ::Visibility ::PUBLIC ,
72
- owner ,
73
- ) )
52
+ reader_signatures = [ RubyIndexer ::Entry ::Signature . new ( [ ] ) ]
53
+ @listener . add_method ( name , loc , reader_signatures )
74
54
75
55
# Writer
76
- @index . add ( RubyIndexer ::Entry ::Method . new (
77
- "#{ name } =" ,
78
- file_path ,
79
- loc ,
80
- loc ,
81
- nil ,
82
- [ RubyIndexer ::Entry ::Signature . new ( [ RubyIndexer ::Entry ::RequiredParameter . new ( name : name . to_sym ) ] ) ] ,
83
- RubyIndexer ::Entry ::Visibility ::PUBLIC ,
84
- owner ,
85
- ) )
56
+ writer_signatures = [
57
+ RubyIndexer ::Entry ::Signature . new ( [ RubyIndexer ::Entry ::RequiredParameter . new ( name : name . to_sym ) ] ) ,
58
+ ]
59
+ @listener . add_method ( "#{ name } =" , loc , writer_signatures )
86
60
end
87
61
88
- sig do
89
- params (
90
- owner : RubyIndexer ::Entry ::Namespace ,
91
- node : Prism ::CallNode ,
92
- ) . void
93
- end
94
- def handle_concern_extend ( owner , node )
95
- arguments = node . arguments &.arguments
62
+ sig { params ( owner : RubyIndexer ::Entry ::Namespace , call_node : Prism ::CallNode ) . void }
63
+ def handle_concern_extend ( owner , call_node )
64
+ arguments = call_node . arguments &.arguments
96
65
return unless arguments
97
66
98
67
arguments . each do |node |
@@ -101,7 +70,7 @@ def handle_concern_extend(owner, node)
101
70
module_name = node . full_name
102
71
next unless module_name == "ActiveSupport::Concern"
103
72
104
- @index . register_included_hook ( owner . name ) do |index , base |
73
+ @listener . register_included_hook do |index , base |
105
74
class_methods_name = "#{ owner . name } ::ClassMethods"
106
75
107
76
if index . indexed? ( class_methods_name )
0 commit comments