11use code_analysis:: {
22 DbIndex , LuaDeclId , LuaDocument , LuaMemberId , LuaMemberKey , LuaMemberOwner , LuaPropertyOwnerId ,
3- LuaType , LuaTypeDeclId , SemanticInfo ,
3+ LuaSignatureId , LuaType , LuaTypeDeclId , SemanticInfo ,
44} ;
55use emmylua_parser:: LuaSyntaxToken ;
66use lsp_types:: { Hover , HoverContents , MarkedString , MarkupContent } ;
@@ -90,6 +90,10 @@ fn build_decl_hover(
9090 let property_owner = LuaPropertyOwnerId :: LuaDecl ( decl_id) ;
9191 add_description ( db, & mut marked_strings, property_owner) ;
9292
93+ if let LuaType :: Signature ( signature_id) = typ {
94+ add_signature_description ( db, & mut marked_strings, signature_id) ;
95+ }
96+
9397 Some ( Hover {
9498 contents : HoverContents :: Array ( marked_strings) ,
9599 range : document. to_lsp_range ( token. text_range ( ) ) ,
@@ -145,6 +149,10 @@ fn build_member_hover(
145149 LuaPropertyOwnerId :: Member ( member_id) ,
146150 ) ;
147151
152+ if let LuaType :: Signature ( signature_id) = typ {
153+ add_signature_description ( db, & mut marked_strings, signature_id) ;
154+ }
155+
148156 Some ( Hover {
149157 contents : HoverContents :: Array ( marked_strings) ,
150158 range : document. to_lsp_range ( token. text_range ( ) ) ,
@@ -156,13 +164,51 @@ fn add_description(
156164 marked_strings : & mut Vec < MarkedString > ,
157165 property_owner : LuaPropertyOwnerId ,
158166) {
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 ( ) ) {
160168 if let Some ( detail) = & property. description {
161169 marked_strings. push ( MarkedString :: from_markdown ( detail. to_string ( ) ) ) ;
162170 }
163171 }
164172}
165173
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+
166212fn build_type_decl_hover (
167213 db : & DbIndex ,
168214 document : & LuaDocument ,
0 commit comments