Skip to content

Commit aa86761

Browse files
committed
support multi see and other tag
1 parent 045765f commit aa86761

File tree

8 files changed

+92
-53
lines changed

8 files changed

+92
-53
lines changed

crates/emmylua_code_analysis/src/compilation/analyzer/doc/type_ref_tags.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,15 +389,15 @@ pub fn analyze_other(analyzer: &mut DocAnalyzer, other: LuaDocTagOther) -> Optio
389389
let tag_name = other.get_tag_name()?;
390390
let description = if let Some(des) = other.get_description() {
391391
let description = preprocess_description(&des.get_description_text(), None);
392-
format!("@*{}* {}", tag_name, description)
392+
description
393393
} else {
394-
format!("@*{}*", tag_name)
394+
"".to_string()
395395
};
396396

397397
analyzer
398398
.db
399399
.get_property_index_mut()
400-
.add_other(analyzer.file_id, owner, description);
400+
.add_other(analyzer.file_id, owner, tag_name, description);
401401

402402
Some(())
403403
}

crates/emmylua_code_analysis/src/db_index/property/mod.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use emmylua_parser::{LuaVersionCondition, VisibilityKind};
66
use property::LuaCommonProperty;
77
pub use property::{LuaDeprecated, LuaExport, LuaExportScope, LuaPropertyId};
88

9-
use crate::FileId;
9+
use crate::{db_index::property::property::LuaTagContent, FileId};
1010

1111
use super::{traits::LuaIndex, LuaSemanticDeclId};
1212

@@ -161,7 +161,11 @@ impl LuaPropertyIndex {
161161
see_content: String,
162162
) -> Option<()> {
163163
let property = self.get_or_create_property(owner_id.clone())?;
164-
property.see_content = Some(Box::new(see_content));
164+
let tag_content = property
165+
.tag_content
166+
.get_or_insert_with(|| Box::new(LuaTagContent::new()));
167+
168+
tag_content.add_tag("see".into(), see_content);
165169

166170
self.in_filed_owner
167171
.entry(file_id)
@@ -175,17 +179,14 @@ impl LuaPropertyIndex {
175179
&mut self,
176180
file_id: FileId,
177181
owner_id: LuaSemanticDeclId,
182+
tag_name: String,
178183
other_content: String,
179184
) -> Option<()> {
180185
let property = self.get_or_create_property(owner_id.clone())?;
181-
if let Some(content) = &property.other_content {
182-
let mut content = content.clone();
183-
content.push_str("\n\n");
184-
content.push_str(&other_content);
185-
property.other_content = Some(content);
186-
} else {
187-
property.other_content = Some(other_content.into());
188-
}
186+
let tag_content = property
187+
.tag_content
188+
.get_or_insert_with(|| Box::new(LuaTagContent::new()));
189+
tag_content.add_tag(tag_name, other_content);
189190

190191
self.in_filed_owner
191192
.entry(file_id)

crates/emmylua_code_analysis/src/db_index/property/property.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ pub struct LuaCommonProperty {
88
pub source: Option<Box<String>>,
99
pub deprecated: Option<LuaDeprecated>,
1010
pub version_conds: Option<Box<Vec<LuaVersionCondition>>>,
11-
pub see_content: Option<Box<String>>,
12-
pub other_content: Option<Box<String>>,
11+
pub tag_content: Option<Box<LuaTagContent>>,
1312
pub export: Option<LuaExport>,
1413
}
1514

@@ -25,6 +24,25 @@ pub enum LuaExportScope {
2524
Namespace,
2625
}
2726

27+
#[derive(Debug, Clone, PartialEq, Eq)]
28+
pub struct LuaTagContent {
29+
pub tags: Vec<(String, String)>,
30+
}
31+
32+
impl LuaTagContent {
33+
pub fn new() -> Self {
34+
Self { tags: Vec::new() }
35+
}
36+
37+
pub fn add_tag(&mut self, tag: String, content: String) {
38+
self.tags.push((tag, content));
39+
}
40+
41+
pub fn get_all_tags(&self) -> &[(String, String)] {
42+
&self.tags
43+
}
44+
}
45+
2846
#[derive(Debug, Clone, PartialEq, Eq)]
2947
pub struct LuaExport {
3048
pub scope: LuaExportScope,
@@ -39,8 +57,7 @@ impl LuaCommonProperty {
3957
source: None,
4058
deprecated: None,
4159
version_conds: None,
42-
see_content: None,
43-
other_content: None,
60+
tag_content: None,
4461
export: None,
4562
}
4663
}

crates/emmylua_doc_cli/src/json_generator/export.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,13 +314,21 @@ fn export_property(db: &DbIndex, semantic_decl: &LuaSemanticDeclId) -> Property
314314
.as_ref()
315315
.and_then(|s| s.to_str())
316316
.map(|s| s.to_string()),
317-
see: property.see_content.as_ref().map(|s| s.to_string()),
318317
deprecated: property.deprecated.is_some(),
319318
deprecation_reason: property.deprecated.as_ref().and_then(|s| match s {
320319
LuaDeprecated::Deprecated => None,
321320
LuaDeprecated::DeprecatedWithMessage(msg) => Some(msg.to_string()),
322321
}),
323-
other: property.other_content.as_ref().map(|s| s.to_string()),
322+
tag_content: property.tag_content.as_ref().map(|tag_content| {
323+
tag_content
324+
.get_all_tags()
325+
.iter()
326+
.map(|(name, content)| TagNameContent {
327+
tag_name: name.clone(),
328+
content: content.clone(),
329+
})
330+
.collect()
331+
}),
324332
},
325333
None => Default::default(),
326334
}

crates/emmylua_doc_cli/src/json_generator/json_types.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,15 @@ pub struct Field {
130130
pub struct Property {
131131
pub description: Option<String>,
132132
pub visibility: Option<String>,
133-
pub see: Option<String>,
134133
pub deprecated: bool,
135134
pub deprecation_reason: Option<String>,
136-
pub other: Option<String>,
135+
pub tag_content: Option<Vec<TagNameContent>>,
136+
}
137+
138+
#[derive(Debug, Serialize, Deserialize, Default)]
139+
pub struct TagNameContent {
140+
pub tag_name: String,
141+
pub content: String,
137142
}
138143

139144
#[derive(Debug, Serialize, Deserialize, Default)]

crates/emmylua_doc_cli/src/markdown_generator/gen/mod.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ fn collect_property(db: &DbIndex, semantic_decl: LuaSemanticDeclId) -> Property
1919
doc_property.description = Some(description.to_string());
2020
}
2121

22-
if let Some(see) = property.see_content.clone() {
23-
doc_property.see = Some(see.to_string());
24-
}
25-
2622
if let Some(deprecated) = &property.deprecated {
2723
match deprecated {
2824
LuaDeprecated::Deprecated => {
@@ -33,8 +29,26 @@ fn collect_property(db: &DbIndex, semantic_decl: LuaSemanticDeclId) -> Property
3329
}
3430
}
3531
}
36-
if let Some(other) = property.other_content.clone() {
37-
doc_property.other = Some(other.to_string());
32+
33+
if let Some(tag_content) = &property.tag_content {
34+
for (tag_name, content) in tag_content.get_all_tags() {
35+
match tag_name.as_str() {
36+
"see" => {
37+
let see_content = doc_property.see.get_or_insert_with(String::new);
38+
if !see_content.is_empty() {
39+
see_content.push_str("\n");
40+
}
41+
see_content.push_str(content);
42+
}
43+
_ => {
44+
let other_content = doc_property.other.get_or_insert_with(String::new);
45+
if !other_content.is_empty() {
46+
other_content.push_str("\n");
47+
}
48+
other_content.push_str(&format!("@{} {}", tag_name, content));
49+
}
50+
}
51+
}
3852
}
3953
}
4054

crates/emmylua_ls/src/handlers/hover/hover_builder.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ pub struct HoverBuilder<'a> {
2424
/// Type expansion, often used for alias types
2525
pub type_expansion: Option<Vec<String>>,
2626
/// see
27-
see_content: Option<String>,
28-
/// other
29-
other_content: Option<String>,
27+
tag_content: Option<Vec<(String, String)>>,
3028

3129
pub is_completion: bool,
3230
trigger_token: Option<LuaSyntaxToken>,
@@ -51,8 +49,7 @@ impl<'a> HoverBuilder<'a> {
5149
is_completion,
5250
trigger_token: token,
5351
type_expansion: None,
54-
see_content: None,
55-
other_content: None,
52+
tag_content: None,
5653
}
5754
}
5855

@@ -146,11 +143,8 @@ impl<'a> HoverBuilder<'a> {
146143
self.add_annotation_description(description);
147144
}
148145

149-
if let Some(see) = desc_info.see_content {
150-
self.see_content = Some(see);
151-
}
152-
if let Some(other) = desc_info.other_content {
153-
self.other_content = Some(other);
146+
if let Some(tag_content) = desc_info.tag_content {
147+
self.tag_content = Some(tag_content);
154148
}
155149

156150
Some(())
@@ -244,14 +238,12 @@ impl<'a> HoverBuilder<'a> {
244238
}
245239
}
246240

247-
if let Some(see_content) = &self.see_content {
248-
content.push_str(&format!("\n@*see* {}\n", see_content));
241+
if let Some(tag_content) = &self.tag_content {
242+
for (tag_name, description) in tag_content {
243+
content.push_str(&format!("\n@*{}* {}\n", tag_name, description));
244+
}
249245
}
250246

251-
if let Some(other) = &self.other_content {
252-
content.push_str("\n\n");
253-
content.push_str(other);
254-
}
255247
content
256248
};
257249

crates/emmylua_ls/src/handlers/hover/hover_humanize.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,19 @@ pub fn infer_prefix_global_name<'a>(
142142
#[derive(Debug, Clone)]
143143
pub struct DescriptionInfo {
144144
pub description: Option<String>,
145-
pub see_content: Option<String>,
146-
pub other_content: Option<String>,
145+
pub tag_content: Option<Vec<(String, String)>>,
147146
}
148147

149148
impl DescriptionInfo {
150149
pub fn new() -> Self {
151150
Self {
152151
description: None,
153-
see_content: None,
154-
other_content: None,
152+
tag_content: None,
155153
}
156154
}
157155

158156
pub fn is_empty(&self) -> bool {
159-
self.description.is_none() && self.see_content.is_none() && self.other_content.is_none()
157+
self.description.is_none() && self.tag_content.is_none()
160158
}
161159
}
162160

@@ -209,11 +207,15 @@ pub fn extract_description_from_property_owner(
209207
result.description = Some(description);
210208
}
211209

212-
if let Some(see) = &property.see_content {
213-
result.see_content = Some(see.to_string());
214-
}
215-
if let Some(other) = &property.other_content {
216-
result.other_content = Some(other.to_string());
210+
if let Some(tag_content) = &property.tag_content {
211+
for (tag_name, description) in tag_content.get_all_tags() {
212+
if result.tag_content.is_none() {
213+
result.tag_content = Some(Vec::new());
214+
}
215+
if let Some(tag_content) = &mut result.tag_content {
216+
tag_content.push((tag_name.clone(), description.clone()));
217+
}
218+
}
217219
}
218220

219221
if result.is_empty() {

0 commit comments

Comments
 (0)