File tree Expand file tree Collapse file tree
crates/emmylua_ls/src/handlers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -160,7 +160,9 @@ fn build_decl_hover(
160160 builder. set_location_path ( member) ;
161161 }
162162
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 ( ) ) ) ;
164166 } else {
165167 if typ. is_const ( ) {
166168 let const_value = hover_const_type ( db, & typ) ;
@@ -245,7 +247,10 @@ fn build_member_hover(
245247
246248 builder. set_location_path ( Some ( & member) ) ;
247249
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+ ) ;
249254 } else {
250255 if typ. is_const ( ) {
251256 let const_value = hover_const_type ( db, & typ) ;
Original file line number Diff line number Diff line change @@ -426,6 +426,7 @@ mod tests {
426426 } ,
427427 ) ) ;
428428 }
429+
429430 #[ test]
430431 fn test_other_file_function ( ) {
431432 let mut ws = ProviderVirtualWorkspace :: new ( ) ;
@@ -449,4 +450,32 @@ mod tests {
449450 } ,
450451 ) ) ;
451452 }
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+ }
452481}
Original file line number Diff line number Diff line change @@ -159,7 +159,7 @@ impl ProviderVirtualWorkspace {
159159 // dbg!(&value);
160160 if value != expect. value {
161161 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: {}" ,
163163 expect. value
164164 ) ;
165165 return false ;
You can’t perform that action at this time.
0 commit comments