@@ -41,51 +41,81 @@ pub fn hover_function_type(
4141 function_member,
4242 func_name,
4343 ) ) ,
44- LuaType :: Signature ( signature_id) => hover_signature_type (
44+ LuaType :: Signature ( signature_id) => {
45+ let type_description = hover_signature_type (
46+ builder,
47+ db,
48+ signature_id. clone ( ) ,
49+ function_member,
50+ func_name,
51+ is_local,
52+ )
53+ . unwrap_or_else ( || {
54+ builder. signature_overload = None ;
55+ format ! ( "function {}" , func_name)
56+ } ) ;
57+ builder. set_type_description ( type_description) ;
58+ } ,
59+ LuaType :: Union ( union) => {
60+ hover_union_function_type ( builder, db, union, function_member, func_name)
61+ }
62+ _ => builder. set_type_description ( format ! ( "function {}" , func_name) ) ,
63+ }
64+ }
65+
66+ fn hover_union_function_type (
67+ builder : & mut HoverBuilder ,
68+ db : & DbIndex ,
69+ union : & LuaUnionType ,
70+ function_member : Option < & LuaMember > ,
71+ func_name : & str ,
72+ ) {
73+ // 泛型处理
74+ if let Some ( call) = builder. get_call_signature ( ) {
75+ builder. set_type_description ( hover_doc_function_type (
4576 builder,
4677 db,
47- signature_id . clone ( ) ,
78+ & call ,
4879 function_member,
4980 func_name,
50- is_local ,
51- )
52- . unwrap_or_else ( || {
53- builder . set_type_description ( format ! ( "function {}" , func_name ) ) ;
54- builder . signature_overload = None ;
55- } ) ,
56- LuaType :: Union ( union ) => {
57- // 泛型处理
58- if let Some ( call ) = builder . get_call_signature ( ) {
59- builder . set_type_description ( hover_doc_function_type (
81+ ) ) ;
82+ return ;
83+ }
84+ let mut overloads = Vec :: new ( ) ;
85+
86+ let types = union . get_types ( ) ;
87+ for typ in types {
88+ match typ {
89+ LuaType :: DocFunction ( lua_func ) => {
90+ overloads . push ( hover_doc_function_type (
6091 builder,
6192 db,
62- & call ,
93+ & lua_func ,
6394 function_member,
6495 func_name,
65- ) )
66- } else {
67- // 将最后一个作为 type_description
68- let mut overloads = Vec :: new ( ) ;
69- for typ in union. get_types ( ) {
70- if let LuaType :: DocFunction ( lua_func) = typ {
71- overloads. push ( hover_doc_function_type (
72- builder,
73- db,
74- & lua_func,
75- function_member,
76- func_name,
77- ) ) ;
78- }
79- }
80- if let Some ( signature) = overloads. pop ( ) {
81- builder. set_type_description ( signature) ;
82- for overload in overloads {
83- builder. add_signature_overload ( overload) ;
84- }
96+ ) ) ;
97+ }
98+ LuaType :: Signature ( signature_id) => {
99+ if let Some ( type_description) = hover_signature_type (
100+ builder,
101+ db,
102+ signature_id. clone ( ) ,
103+ function_member,
104+ func_name,
105+ false ,
106+ ) {
107+ overloads. push ( type_description) ;
85108 }
86109 }
110+ _ => { }
111+ }
112+ }
113+ // 将最后一个作为 type_description
114+ if let Some ( type_description) = overloads. pop ( ) {
115+ builder. set_type_description ( type_description) ;
116+ for overload in overloads {
117+ builder. add_signature_overload ( overload) ;
87118 }
88- _ => builder. set_type_description ( format ! ( "function {}" , func_name) ) ,
89119 }
90120}
91121
@@ -167,7 +197,7 @@ fn hover_signature_type(
167197 owner_member : Option < & LuaMember > ,
168198 func_name : & str ,
169199 is_local : bool ,
170- ) -> Option < ( ) > {
200+ ) -> Option < String > {
171201 let signature = db. get_signature_index ( ) . get ( & signature_id) ?;
172202 let call_signature = builder. get_call_signature ( ) ;
173203
@@ -235,9 +265,8 @@ fn hover_signature_type(
235265 if let Some ( call_signature) = & call_signature {
236266 if call_signature. get_params ( ) == signature. get_type_params ( ) {
237267 // 如果具有完全匹配的签名, 那么将其设置为当前签名, 且不显示重载
238- builder. set_type_description ( result) ;
239268 builder. signature_overload = None ;
240- return Some ( ( ) ) ;
269+ return Some ( result ) ;
241270 }
242271 }
243272 result
@@ -273,21 +302,21 @@ fn hover_signature_type(
273302 if let Some ( call_signature) = & call_signature {
274303 if * call_signature == * * overload {
275304 // 如果具有完全匹配的签名, 那么将其设置为当前签名, 且不显示重载
276- builder. set_type_description ( result) ;
277305 builder. signature_overload = None ;
278- return Some ( ( ) ) ;
306+ return Some ( result ) ;
279307 }
280308 } ;
281309 overloads. push ( result) ;
282310 }
283311 overloads
284312 } ;
285313
286- builder . set_type_description ( signature_info ) ;
314+ // 设置重载信息
287315 for overload in overloads {
288316 builder. add_signature_overload ( overload) ;
289317 }
290- Some ( ( ) )
318+
319+ Some ( signature_info)
291320}
292321
293322fn build_signature_rets (
0 commit comments