|
1 | 1 | use std::collections::HashMap; |
2 | 2 |
|
3 | 3 | use emmylua_parser::{ |
4 | | - LuaAssignStat, LuaAst, LuaAstNode, LuaAstToken, LuaCommentOwner, LuaDocDescriptionOwner, |
5 | | - LuaDocGenericDeclList, LuaDocTagAlias, LuaDocTagClass, LuaDocTagEnum, LuaDocTagGeneric, |
6 | | - LuaFuncStat, LuaLocalName, LuaLocalStat, LuaNameExpr, LuaSyntaxId, LuaSyntaxKind, LuaTokenKind, |
7 | | - LuaVarExpr, |
| 4 | + LuaAssignStat, LuaAst, LuaAstNode, LuaAstToken, LuaCommentOwner, LuaDocDescription, |
| 5 | + LuaDocDescriptionOwner, LuaDocGenericDeclList, LuaDocTagAlias, LuaDocTagClass, LuaDocTagEnum, |
| 6 | + LuaDocTagGeneric, LuaFuncStat, LuaLocalName, LuaLocalStat, LuaNameExpr, LuaSyntaxId, |
| 7 | + LuaSyntaxKind, LuaTokenKind, LuaVarExpr, |
8 | 8 | }; |
9 | 9 | use rowan::TextRange; |
10 | 10 |
|
11 | | -use crate::db_index::{ |
12 | | - LuaDeclId, LuaDeclTypeKind, LuaMemberId, LuaPropertyOwnerId, LuaSignatureId, LuaType, |
| 11 | +use crate::{ |
| 12 | + db_index::{ |
| 13 | + LuaDeclId, LuaDeclTypeKind, LuaMemberId, LuaPropertyOwnerId, LuaSignatureId, LuaType, |
| 14 | + }, |
| 15 | + LuaTypeDeclId, |
13 | 16 | }; |
14 | 17 |
|
15 | 18 | use super::{ |
@@ -62,21 +65,45 @@ pub fn analyze_class(analyzer: &mut DocAnalyzer, tag: LuaDocTagClass) -> Option< |
62 | 65 | } |
63 | 66 | } |
64 | 67 |
|
65 | | - if let Some(description) = tag.get_description() { |
66 | | - let description_text = preprocess_description(&description.get_description_text()); |
67 | | - if !description_text.is_empty() { |
68 | | - analyzer.db.get_property_index_mut().add_description( |
69 | | - file_id, |
70 | | - LuaPropertyOwnerId::TypeDecl(class_decl_id.clone()), |
71 | | - description_text, |
72 | | - ); |
73 | | - } |
74 | | - } |
| 68 | + add_description_for_type_decl(analyzer, &class_decl_id, tag.get_description()); |
75 | 69 |
|
76 | 70 | bind_def_type(analyzer, LuaType::Def(class_decl_id.clone())); |
77 | 71 | Some(()) |
78 | 72 | } |
79 | 73 |
|
| 74 | +fn add_description_for_type_decl( |
| 75 | + analyzer: &mut DocAnalyzer, |
| 76 | + type_decl_id: &LuaTypeDeclId, |
| 77 | + description: Option<LuaDocDescription>, |
| 78 | +) { |
| 79 | + let mut description_text = String::new(); |
| 80 | + |
| 81 | + let comment = analyzer.comment.clone(); |
| 82 | + if let Some(description) = comment.get_description() { |
| 83 | + let description = preprocess_description(&description.get_description_text()); |
| 84 | + if !description.is_empty() { |
| 85 | + description_text.push_str(&description); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + if let Some(description) = description { |
| 90 | + let description = preprocess_description(&description.get_description_text()); |
| 91 | + if !description.is_empty() { |
| 92 | + if !description_text.is_empty() { |
| 93 | + description_text.push_str("\n\n"); |
| 94 | + } |
| 95 | + |
| 96 | + description_text.push_str(&description); |
| 97 | + } |
| 98 | + } |
| 99 | + |
| 100 | + analyzer.db.get_property_index_mut().add_description( |
| 101 | + analyzer.file_id, |
| 102 | + LuaPropertyOwnerId::TypeDecl(type_decl_id.clone()), |
| 103 | + description_text, |
| 104 | + ); |
| 105 | +} |
| 106 | + |
80 | 107 | pub fn analyze_enum(analyzer: &mut DocAnalyzer, tag: LuaDocTagEnum) -> Option<()> { |
81 | 108 | let file_id = analyzer.file_id; |
82 | 109 | let name = tag.get_name_token()?.get_name_text().to_string(); |
@@ -107,16 +134,8 @@ pub fn analyze_enum(analyzer: &mut DocAnalyzer, tag: LuaDocTagEnum) -> Option<() |
107 | 134 | enum_decl.add_enum_base(base_type); |
108 | 135 | } |
109 | 136 |
|
110 | | - if let Some(description) = tag.get_description() { |
111 | | - let description_text = preprocess_description(&description.get_description_text()); |
112 | | - if !description_text.is_empty() { |
113 | | - analyzer.db.get_property_index_mut().add_description( |
114 | | - file_id, |
115 | | - LuaPropertyOwnerId::TypeDecl(enum_decl_id.clone()), |
116 | | - description_text, |
117 | | - ); |
118 | | - } |
119 | | - } |
| 137 | + let description = tag.get_description(); |
| 138 | + add_description_for_type_decl(analyzer, &enum_decl_id, description); |
120 | 139 |
|
121 | 140 | bind_def_type(analyzer, LuaType::Def(enum_decl_id.clone())); |
122 | 141 |
|
@@ -167,16 +186,8 @@ pub fn analyze_alias(analyzer: &mut DocAnalyzer, tag: LuaDocTagAlias) -> Option< |
167 | 186 |
|
168 | 187 | alias.add_alias_origin(origin_type); |
169 | 188 |
|
170 | | - let description_text = tag.get_description()?.get_description_text(); |
171 | | - if description_text.is_empty() { |
172 | | - return None; |
173 | | - } |
174 | | - let description_text = preprocess_description(&description_text); |
175 | | - analyzer.db.get_property_index_mut().add_description( |
176 | | - file_id, |
177 | | - LuaPropertyOwnerId::TypeDecl(alias_decl_id.clone()), |
178 | | - description_text, |
179 | | - ); |
| 189 | + let description = tag.get_description(); |
| 190 | + add_description_for_type_decl(analyzer, &alias_decl_id, description); |
180 | 191 |
|
181 | 192 | Some(()) |
182 | 193 | } |
|
0 commit comments