@@ -7,12 +7,15 @@ use emmylua_code_analysis::{
77} ;
88use emmylua_parser:: { LuaAstNode , LuaDocTagField , LuaDocType } ;
99
10- use crate :: handlers:: hover:: {
11- hover_humanize:: {
12- extract_description_from_property_owner, extract_owner_name_from_element,
13- hover_humanize_type, DescriptionInfo ,
10+ use crate :: handlers:: {
11+ definition:: extract_semantic_decl_from_signature,
12+ hover:: {
13+ hover_humanize:: {
14+ extract_description_from_property_owner, extract_owner_name_from_element,
15+ hover_humanize_type, DescriptionInfo ,
16+ } ,
17+ infer_prefix_global_name, HoverBuilder ,
1418 } ,
15- infer_prefix_global_name, HoverBuilder ,
1619} ;
1720
1821#[ derive( Debug , Clone ) ]
@@ -87,6 +90,41 @@ pub fn hover_function_type(
8790 _ => None ,
8891 } ;
8992
93+ // 如果函数定义来自于其他文件, 我们需要添加原始的注释信息. 参考`test_other_file_function`
94+ if let LuaType :: Signature ( signature_id) = typ {
95+ if let Some ( semantic_id) =
96+ extract_semantic_decl_from_signature ( builder. compilation , & signature_id)
97+ {
98+ if semantic_id != * semantic_decl_id {
99+ // signature 的原始定义的描述信息
100+ if let Some ( origin_description) = extract_description_from_property_owner (
101+ & builder. semantic_model ,
102+ & semantic_id,
103+ ) {
104+ match & mut function_info. description {
105+ Some ( current_description) => {
106+ // 如果描述不为空, 则合并描述
107+ if let Some ( description) = origin_description. description {
108+ if current_description. description . is_none ( ) {
109+ current_description. description = Some ( description) ;
110+ } else {
111+ current_description. description = Some ( format ! (
112+ "{}\n {}" ,
113+ current_description. description. take( ) ?,
114+ description
115+ ) ) ;
116+ }
117+ }
118+ }
119+ None => {
120+ function_info. description = Some ( origin_description) ;
121+ }
122+ }
123+ }
124+ }
125+ }
126+ }
127+
90128 // 如果当前类型是 Union,传入已处理的类型集合
91129 let result = match typ {
92130 LuaType :: Union ( _) => process_single_function_type_with_exclusions (
0 commit comments