File tree Expand file tree Collapse file tree 3 files changed +37
-3
lines changed
crates/emmylua_ls/src/handlers Expand file tree Collapse file tree 3 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -160,7 +160,9 @@ fn build_decl_hover(
160
160
builder. set_location_path ( member) ;
161
161
}
162
162
163
- builder. add_signature_params_rets_description ( typ) ;
163
+ // `typ`此时可能是泛型实例化后的类型, 所以我们需要从member获取原始类型
164
+ builder
165
+ . add_signature_params_rets_description ( builder. semantic_model . get_type ( decl_id. into ( ) ) ) ;
164
166
} else {
165
167
if typ. is_const ( ) {
166
168
let const_value = hover_const_type ( db, & typ) ;
@@ -245,7 +247,10 @@ fn build_member_hover(
245
247
246
248
builder. set_location_path ( Some ( & member) ) ;
247
249
248
- builder. add_signature_params_rets_description ( typ) ;
250
+ // `typ`此时可能是泛型实例化后的类型, 所以我们需要从member获取原始类型
251
+ builder. add_signature_params_rets_description (
252
+ builder. semantic_model . get_type ( member. get_id ( ) . into ( ) ) ,
253
+ ) ;
249
254
} else {
250
255
if typ. is_const ( ) {
251
256
let const_value = hover_const_type ( db, & typ) ;
Original file line number Diff line number Diff line change @@ -426,6 +426,7 @@ mod tests {
426
426
} ,
427
427
) ) ;
428
428
}
429
+
429
430
#[ test]
430
431
fn test_other_file_function ( ) {
431
432
let mut ws = ProviderVirtualWorkspace :: new ( ) ;
@@ -449,4 +450,32 @@ mod tests {
449
450
} ,
450
451
) ) ;
451
452
}
453
+
454
+ #[ test]
455
+ fn test_hover_generic_function_params_description ( ) {
456
+ let mut ws = ProviderVirtualWorkspace :: new ( ) ;
457
+ ws. def_file (
458
+ "a.lua" ,
459
+ r#"
460
+ ---@class RingBuffer<T>
461
+ local RingBuffer = {}
462
+
463
+ ---@param index integer 索引
464
+ ---@return T? item
465
+ function RingBuffer:get(index)
466
+ end
467
+
468
+ "# ,
469
+ ) ;
470
+ assert ! ( ws. check_hover(
471
+ r#"
472
+ ---@type RingBuffer<string>
473
+ local RingBuffer
474
+ RingBuffer:<??>get(1)
475
+ "# ,
476
+ VirtualHoverResult {
477
+ value: "```lua\n (method) RingBuffer:get(index: integer) -> string?\n ```\n \n ---\n \n @*param* `index` — 索引" . to_string( ) ,
478
+ } ,
479
+ ) ) ;
480
+ }
452
481
}
Original file line number Diff line number Diff line change @@ -159,7 +159,7 @@ impl ProviderVirtualWorkspace {
159
159
// dbg!(&value);
160
160
if value != expect. value {
161
161
eprintln ! (
162
- "Hover content does not match expected value left : {value},\n right: {}" ,
162
+ "Hover content does not match expected value \n left : {value},\n right: {}" ,
163
163
expect. value
164
164
) ;
165
165
return false ;
You can’t perform that action at this time.
0 commit comments