1
1
use code_analysis:: {
2
2
DbIndex , LuaDeclId , LuaDocument , LuaMemberId , LuaMemberKey , LuaMemberOwner , LuaPropertyOwnerId ,
3
- LuaType , LuaTypeDeclId , SemanticInfo ,
3
+ LuaSignatureId , LuaType , LuaTypeDeclId , SemanticInfo ,
4
4
} ;
5
5
use emmylua_parser:: LuaSyntaxToken ;
6
6
use lsp_types:: { Hover , HoverContents , MarkedString , MarkupContent } ;
@@ -90,6 +90,10 @@ fn build_decl_hover(
90
90
let property_owner = LuaPropertyOwnerId :: LuaDecl ( decl_id) ;
91
91
add_description ( db, & mut marked_strings, property_owner) ;
92
92
93
+ if let LuaType :: Signature ( signature_id) = typ {
94
+ add_signature_description ( db, & mut marked_strings, signature_id) ;
95
+ }
96
+
93
97
Some ( Hover {
94
98
contents : HoverContents :: Array ( marked_strings) ,
95
99
range : document. to_lsp_range ( token. text_range ( ) ) ,
@@ -145,6 +149,10 @@ fn build_member_hover(
145
149
LuaPropertyOwnerId :: Member ( member_id) ,
146
150
) ;
147
151
152
+ if let LuaType :: Signature ( signature_id) = typ {
153
+ add_signature_description ( db, & mut marked_strings, signature_id) ;
154
+ }
155
+
148
156
Some ( Hover {
149
157
contents : HoverContents :: Array ( marked_strings) ,
150
158
range : document. to_lsp_range ( token. text_range ( ) ) ,
@@ -156,13 +164,51 @@ fn add_description(
156
164
marked_strings : & mut Vec < MarkedString > ,
157
165
property_owner : LuaPropertyOwnerId ,
158
166
) {
159
- if let Some ( property) = db. get_property_index ( ) . get_property ( property_owner) {
167
+ if let Some ( property) = db. get_property_index ( ) . get_property ( property_owner. clone ( ) ) {
160
168
if let Some ( detail) = & property. description {
161
169
marked_strings. push ( MarkedString :: from_markdown ( detail. to_string ( ) ) ) ;
162
170
}
163
171
}
164
172
}
165
173
174
+ fn add_signature_description (
175
+ db : & DbIndex ,
176
+ marked_strings : & mut Vec < MarkedString > ,
177
+ signature_id : LuaSignatureId ,
178
+ ) -> Option < ( ) > {
179
+ let signature = db. get_signature_index ( ) . get ( & signature_id) ?;
180
+ let param_count = signature. params . len ( ) ;
181
+ let mut s = String :: new ( ) ;
182
+ for i in 0 ..param_count {
183
+ let param_info = match signature. get_param_info_by_id ( i) {
184
+ Some ( info) => info,
185
+ None => continue ,
186
+ } ;
187
+
188
+ s. push_str ( & format ! ( "@param `{}`" , param_info. name) ) ;
189
+ if let Some ( description) = & param_info. description {
190
+ s. push_str ( & format ! ( " - {}" , description) ) ;
191
+ }
192
+ s. push_str ( "\n " ) ;
193
+ }
194
+
195
+ for return_info in & signature. return_docs {
196
+ s. push_str ( "@return " ) ;
197
+ if let Some ( name) = & return_info. name {
198
+ s. push_str ( & format ! ( "`{}`" , name) ) ;
199
+ }
200
+ if let Some ( description) = & return_info. description {
201
+ s. push_str ( & format ! ( " - {}" , description) ) ;
202
+ }
203
+ s. push_str ( "\n " ) ;
204
+ }
205
+
206
+ if !s. is_empty ( ) {
207
+ marked_strings. push ( MarkedString :: from_markdown ( s) ) ;
208
+ }
209
+ Some ( ( ) )
210
+ }
211
+
166
212
fn build_type_decl_hover (
167
213
db : & DbIndex ,
168
214
document : & LuaDocument ,
0 commit comments