@@ -37,7 +37,54 @@ class HoverTest < ActiveSupport::TestCase
37
37
stub_http_request ( "200" , expected_response . to_json )
38
38
@client . stubs ( check_if_server_is_running! : true )
39
39
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
41
88
42
89
assert_equal ( <<~CONTENT , response . contents . value )
43
90
[Schema](file://#{ @client . root } /db/schema.rb)
@@ -65,7 +112,12 @@ class HoverTest < ActiveSupport::TestCase
65
112
stub_http_request ( "200" , expected_response . to_json )
66
113
@client . stubs ( check_if_server_is_running! : true )
67
114
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
69
121
70
122
assert_includes (
71
123
response . contents . value ,
@@ -82,7 +134,12 @@ class HoverTest < ActiveSupport::TestCase
82
134
stub_http_request ( "200" , expected_response . to_json )
83
135
@client . stubs ( check_if_server_is_running! : true )
84
136
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
86
143
87
144
refute_match ( /Schema/ , response . contents . value )
88
145
end
@@ -116,7 +173,11 @@ class HoverTest < ActiveSupport::TestCase
116
173
end
117
174
118
175
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
120
181
121
182
assert_match ( /\[ Rails Document: `ActiveRecord::Base`\] / , value )
122
183
assert_match ( %r{\( https://api\. rubyonrails\. org/.*Base\. html\) } , value )
@@ -129,7 +190,11 @@ def hover_on_source(source, position)
129
190
store = RubyLsp ::Store . new
130
191
store . set ( uri : uri , source : source , version : 1 )
131
192
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 (
133
198
{
134
199
method : "textDocument/hover" ,
135
200
params : {
0 commit comments