File tree 3 files changed +36
-0
lines changed
lib/ruby_lsp/ruby_lsp_rails
3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,8 @@ def resolve_association_target(params)
152
152
}
153
153
end
154
154
155
+ # Clear the cache so that we get the latest associations.
156
+ const . clear_reflections_cache
155
157
association_klass = const . reflect_on_association ( params [ :association_name ] . intern ) . klass
156
158
157
159
source_location = Object . const_source_location ( association_klass . to_s )
Original file line number Diff line number Diff line change
1
+ # typed: strict
2
+ # frozen_string_literal: true
3
+
4
+ class User
5
+ class << self
6
+ sig { params ( association_name : Symbol ) . void }
7
+ def has_many ( association_name )
8
+ end
9
+
10
+ sig { returns ( T ::Hash [ String , T . untyped ] ) }
11
+ def reflections
12
+ end
13
+ end
14
+ end
Original file line number Diff line number Diff line change @@ -103,6 +103,26 @@ def <(other)
103
103
assert_nil ( response . fetch ( :result ) )
104
104
end
105
105
106
+ test "resolve association reflect the latest associations" do
107
+ response = @server . execute (
108
+ "association_target_location" ,
109
+ { model_name : "User" , association_name : :memberships } ,
110
+ )
111
+ assert_nil ( response . fetch ( :result ) )
112
+
113
+ User . has_many ( :memberships )
114
+
115
+ response = @server . execute (
116
+ "association_target_location" ,
117
+ { model_name : "User" , association_name : :memberships } ,
118
+ )
119
+
120
+ location = response [ :result ] [ :location ]
121
+ assert_match ( %r{test/dummy/app/models/membership.rb:3$} , location )
122
+ ensure
123
+ User . reflections . delete ( "memberships" )
124
+ end
125
+
106
126
test "resolve association handles class_name option" do
107
127
response = @server . execute (
108
128
"association_target_location" ,
You can’t perform that action at this time.
0 commit comments