@@ -41,51 +41,81 @@ pub fn hover_function_type(
41
41
function_member,
42
42
func_name,
43
43
) ) ,
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 (
45
76
builder,
46
77
db,
47
- signature_id . clone ( ) ,
78
+ & call ,
48
79
function_member,
49
80
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 (
60
91
builder,
61
92
db,
62
- & call ,
93
+ & lua_func ,
63
94
function_member,
64
95
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) ;
85
108
}
86
109
}
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) ;
87
118
}
88
- _ => builder. set_type_description ( format ! ( "function {}" , func_name) ) ,
89
119
}
90
120
}
91
121
@@ -172,7 +202,7 @@ fn hover_signature_type(
172
202
owner_member : Option < & LuaMember > ,
173
203
func_name : & str ,
174
204
is_local : bool ,
175
- ) -> Option < ( ) > {
205
+ ) -> Option < String > {
176
206
let signature = db. get_signature_index ( ) . get ( & signature_id) ?;
177
207
let call_signature = builder. get_call_signature ( ) ;
178
208
@@ -240,9 +270,8 @@ fn hover_signature_type(
240
270
if let Some ( call_signature) = & call_signature {
241
271
if call_signature. get_params ( ) == signature. get_type_params ( ) {
242
272
// 如果具有完全匹配的签名, 那么将其设置为当前签名, 且不显示重载
243
- builder. set_type_description ( result) ;
244
273
builder. signature_overload = None ;
245
- return Some ( ( ) ) ;
274
+ return Some ( result ) ;
246
275
}
247
276
}
248
277
result
@@ -278,21 +307,21 @@ fn hover_signature_type(
278
307
if let Some ( call_signature) = & call_signature {
279
308
if * call_signature == * * overload {
280
309
// 如果具有完全匹配的签名, 那么将其设置为当前签名, 且不显示重载
281
- builder. set_type_description ( result) ;
282
310
builder. signature_overload = None ;
283
- return Some ( ( ) ) ;
311
+ return Some ( result ) ;
284
312
}
285
313
} ;
286
314
overloads. push ( result) ;
287
315
}
288
316
overloads
289
317
} ;
290
318
291
- builder . set_type_description ( signature_info ) ;
319
+ // 设置重载信息
292
320
for overload in overloads {
293
321
builder. add_signature_overload ( overload) ;
294
322
}
295
- Some ( ( ) )
323
+
324
+ Some ( signature_info)
296
325
}
297
326
298
327
fn build_signature_rets (
0 commit comments