3
3
4
4
module RubyLsp
5
5
module Rails
6
- class IndexingEnhancement
6
+ class IndexingEnhancement < RubyIndexer :: Enhancement
7
7
extend T ::Sig
8
- include RubyIndexer ::Enhancement
8
+
9
+ sig { params ( index : RubyIndexer ::Index ) . void }
10
+ def initialize ( index )
11
+ super
12
+ @index = index
13
+ end
9
14
10
15
sig do
11
16
override . params (
12
- index : RubyIndexer ::Index ,
13
17
owner : T . nilable ( RubyIndexer ::Entry ::Namespace ) ,
14
18
node : Prism ::CallNode ,
15
19
file_path : String ,
@@ -19,24 +23,23 @@ class IndexingEnhancement
19
23
) ,
20
24
) . void
21
25
end
22
- def on_call_node ( index , owner , node , file_path , code_units_cache )
26
+ def on_call_node_enter ( owner , node , file_path , code_units_cache )
23
27
return unless owner
24
28
25
29
name = node . name
26
30
27
31
case name
28
32
when :extend
29
- handle_concern_extend ( index , owner , node )
33
+ handle_concern_extend ( owner , node )
30
34
when :has_one , :has_many , :belongs_to , :has_and_belongs_to_many
31
- handle_association ( index , owner , node , file_path , code_units_cache )
35
+ handle_association ( owner , node , file_path , code_units_cache )
32
36
end
33
37
end
34
38
35
39
private
36
40
37
41
sig do
38
42
params (
39
- index : RubyIndexer ::Index ,
40
43
owner : RubyIndexer ::Entry ::Namespace ,
41
44
node : Prism ::CallNode ,
42
45
file_path : String ,
@@ -46,7 +49,7 @@ def on_call_node(index, owner, node, file_path, code_units_cache)
46
49
) ,
47
50
) . void
48
51
end
49
- def handle_association ( index , owner , node , file_path , code_units_cache )
52
+ def handle_association ( owner , node , file_path , code_units_cache )
50
53
arguments = node . arguments &.arguments
51
54
return unless arguments
52
55
@@ -64,7 +67,7 @@ def handle_association(index, owner, node, file_path, code_units_cache)
64
67
loc = RubyIndexer ::Location . from_prism_location ( name_arg . location , code_units_cache )
65
68
66
69
# Reader
67
- index . add ( RubyIndexer ::Entry ::Method . new (
70
+ @ index. add ( RubyIndexer ::Entry ::Method . new (
68
71
name ,
69
72
file_path ,
70
73
loc ,
@@ -76,7 +79,7 @@ def handle_association(index, owner, node, file_path, code_units_cache)
76
79
) )
77
80
78
81
# Writer
79
- index . add ( RubyIndexer ::Entry ::Method . new (
82
+ @ index. add ( RubyIndexer ::Entry ::Method . new (
80
83
"#{ name } =" ,
81
84
file_path ,
82
85
loc ,
@@ -90,12 +93,11 @@ def handle_association(index, owner, node, file_path, code_units_cache)
90
93
91
94
sig do
92
95
params (
93
- index : RubyIndexer ::Index ,
94
96
owner : RubyIndexer ::Entry ::Namespace ,
95
97
node : Prism ::CallNode ,
96
98
) . void
97
99
end
98
- def handle_concern_extend ( index , owner , node )
100
+ def handle_concern_extend ( owner , node )
99
101
arguments = node . arguments &.arguments
100
102
return unless arguments
101
103
@@ -105,7 +107,7 @@ def handle_concern_extend(index, owner, node)
105
107
module_name = node . full_name
106
108
next unless module_name == "ActiveSupport::Concern"
107
109
108
- index . register_included_hook ( owner . name ) do |index , base |
110
+ @ index. register_included_hook ( owner . name ) do |index , base |
109
111
class_methods_name = "#{ owner . name } ::ClassMethods"
110
112
111
113
if index . indexed? ( class_methods_name )
0 commit comments