@@ -37,7 +37,54 @@ class HoverTest < ActiveSupport::TestCase
3737 stub_http_request ( "200" , expected_response . to_json )
3838 @client . stubs ( check_if_server_is_running! : true )
3939
40- response = hover_on_source ( "User" , { line : 0 , character : 0 } )
40+ response = hover_on_source ( <<~RUBY , { line : 3 , character : 0 } )
41+ class User < ApplicationRecord
42+ end
43+
44+ User
45+ RUBY
46+
47+ assert_equal ( <<~CONTENT , response . contents . value )
48+ [Schema](file://#{ @client . root } /db/schema.rb)
49+
50+ **id**: integer
51+
52+ **first_name**: string
53+
54+ **last_name**: string
55+
56+ **age**: integer
57+
58+ **created_at**: datetime
59+
60+ **updated_at**: datetime
61+ CONTENT
62+ end
63+
64+ test "return column information for namespaced models" do
65+ expected_response = {
66+ schema_file : "#{ @client . root } /db/schema.rb" ,
67+ columns : [
68+ [ "id" , "integer" ] ,
69+ [ "first_name" , "string" ] ,
70+ [ "last_name" , "string" ] ,
71+ [ "age" , "integer" ] ,
72+ [ "created_at" , "datetime" ] ,
73+ [ "updated_at" , "datetime" ] ,
74+ ] ,
75+ }
76+
77+ stub_http_request ( "200" , expected_response . to_json )
78+ @client . stubs ( check_if_server_is_running! : true )
79+
80+ response = hover_on_source ( <<~RUBY , { line : 4 , character : 6 } )
81+ module Blog
82+ class User < ApplicationRecord
83+ end
84+ end
85+
86+ Blog::User
87+ RUBY
4188
4289 assert_equal ( <<~CONTENT , response . contents . value )
4390 [Schema](file://#{ @client . root } /db/schema.rb)
@@ -65,7 +112,12 @@ class HoverTest < ActiveSupport::TestCase
65112 stub_http_request ( "200" , expected_response . to_json )
66113 @client . stubs ( check_if_server_is_running! : true )
67114
68- response = hover_on_source ( "User" , { line : 0 , character : 0 } )
115+ response = hover_on_source ( <<~RUBY , { line : 3 , character : 0 } )
116+ class User < ApplicationRecord
117+ end
118+
119+ User
120+ RUBY
69121
70122 assert_includes (
71123 response . contents . value ,
@@ -82,7 +134,12 @@ class HoverTest < ActiveSupport::TestCase
82134 stub_http_request ( "200" , expected_response . to_json )
83135 @client . stubs ( check_if_server_is_running! : true )
84136
85- response = hover_on_source ( "User" , { line : 0 , character : 0 } )
137+ response = hover_on_source ( <<~RUBY , { line : 3 , character : 0 } )
138+ class User < ApplicationRecord
139+ end
140+
141+ User
142+ RUBY
86143
87144 refute_match ( /Schema/ , response . contents . value )
88145 end
@@ -116,7 +173,11 @@ class HoverTest < ActiveSupport::TestCase
116173 end
117174
118175 test "shows documentation for Rails constants" do
119- value = hover_on_source ( "ActiveRecord::Base" , { line : 0 , character : 14 } ) . contents . value
176+ value = hover_on_source ( <<~RUBY , { line : 2 , character : 14 } ) . contents . value
177+ class ActiveRecord::Base
178+ end
179+ ActiveRecord::Base
180+ RUBY
120181
121182 assert_match ( /\[ Rails Document: `ActiveRecord::Base`\] / , value )
122183 assert_match ( %r{\( https://api\. rubyonrails\. org/.*Base\. html\) } , value )
@@ -129,7 +190,11 @@ def hover_on_source(source, position)
129190 store = RubyLsp ::Store . new
130191 store . set ( uri : uri , source : source , version : 1 )
131192
132- response = RubyLsp ::Executor . new ( store , @message_queue ) . execute (
193+ executor = RubyLsp ::Executor . new ( store , @message_queue )
194+ executor . instance_variable_get ( :@index ) . index_single (
195+ RubyIndexer ::IndexablePath . new ( nil , T . must ( uri . to_standardized_path ) ) , source
196+ )
197+ response = executor . execute (
133198 {
134199 method : "textDocument/hover" ,
135200 params : {
0 commit comments