Skip to content

Commit 7d56390

Browse files
committed
Support for Descriptions Above and After Tags
1 parent 0dc5f80 commit 7d56390

File tree

19 files changed

+484
-192
lines changed

19 files changed

+484
-192
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55
---
66
## [0.8.2] - Unreleased
77

8+
### ✨ Added
9+
- **Support for Descriptions Above and After Tags**: You can now add descriptions both above a tag (as a preceding comment) and after a tag (inline). The description will be associated with the corresponding tag.
10+
```lua
11+
---@class A
12+
--- Description below (applies to the @field a)
13+
---@field a integer inline-description
14+
---@field b integer # description after hash
15+
--- Description above (applies to the @field b)
16+
---@field c integer inline-description
17+
local a = {}
18+
```
19+
20+
821
### 🐛 Fixed
922
- **Enum Variable Parameter Issue**: Fixed a crash issue when checking enum variable as parameter
1023

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ members = [
88
[workspace.dependencies]
99
# local
1010
emmylua_code_analysis = { path = "crates/emmylua_code_analysis", version = "0.8.1" }
11-
emmylua_parser = { path = "crates/emmylua_parser", version = "0.10.8" }
11+
emmylua_parser = { path = "crates/emmylua_parser", version = "0.11.0" }
1212
emmylua_diagnostic_macro = { path = "crates/emmylua_diagnostic_macro", version = "0.4.0" }
1313

1414
# external

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use emmylua_parser::{
66
};
77

88
use crate::{
9+
compilation::analyzer::doc::preprocess_description,
910
db_index::{
1011
LuaMember, LuaMemberKey, LuaMemberOwner, LuaOperator, LuaOperatorMetaMethod,
1112
LuaSemanticDeclId, LuaType,
@@ -60,11 +61,19 @@ pub fn analyze_field(analyzer: &mut DocAnalyzer, tag: LuaDocTagField) -> Option<
6061
field_type = TypeOps::Union.apply(analyzer.db, &field_type, &LuaType::Nil);
6162
}
6263

63-
let description = if let Some(description) = tag.get_description() {
64-
Some(description.get_description_text().to_string())
65-
} else {
66-
None
67-
};
64+
let mut description = String::new();
65+
66+
for desc in tag.get_descriptions() {
67+
let mut desc_text = desc.get_description_text().to_string();
68+
if !desc_text.is_empty() {
69+
let text = preprocess_description(&mut desc_text);
70+
if !description.is_empty() {
71+
description.push_str("\n\n");
72+
}
73+
74+
description.push_str(&text);
75+
}
76+
}
6877

6978
let field_key = tag.get_field_key()?;
7079
let key = match field_key {
@@ -134,7 +143,7 @@ pub fn analyze_field(analyzer: &mut DocAnalyzer, tag: LuaDocTagField) -> Option<
134143
);
135144
}
136145

137-
if let Some(description) = description {
146+
if !description.is_empty() {
138147
analyzer.db.get_property_index_mut().add_description(
139148
analyzer.file_id,
140149
property_owner.clone(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
profile::Profile,
1414
FileId,
1515
};
16-
use emmylua_parser::{LuaAstNode, LuaComment, LuaDocDescriptionOwner, LuaSyntaxNode};
16+
use emmylua_parser::{LuaAstNode, LuaComment, LuaSyntaxNode};
1717
use file_generic_index::FileGenericIndex;
1818
use tags::get_owner_id;
1919

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn analyze_class(analyzer: &mut DocAnalyzer, tag: LuaDocTagClass) -> Option<
6161
}
6262
}
6363

64-
add_description_for_type_decl(analyzer, &class_decl_id, tag.get_description());
64+
add_description_for_type_decl(analyzer, &class_decl_id, tag.get_descriptions());
6565

6666
bind_def_type(analyzer, LuaType::Def(class_decl_id.clone()));
6767
Some(())
@@ -70,19 +70,11 @@ pub fn analyze_class(analyzer: &mut DocAnalyzer, tag: LuaDocTagClass) -> Option<
7070
fn add_description_for_type_decl(
7171
analyzer: &mut DocAnalyzer,
7272
type_decl_id: &LuaTypeDeclId,
73-
description: Option<LuaDocDescription>,
73+
descriptions: Vec<LuaDocDescription>,
7474
) {
7575
let mut description_text = String::new();
7676

77-
let comment = analyzer.comment.clone();
78-
if let Some(description) = comment.get_description() {
79-
let description = preprocess_description(&description.get_description_text());
80-
if !description.is_empty() {
81-
description_text.push_str(&description);
82-
}
83-
}
84-
85-
if let Some(description) = description {
77+
for description in descriptions {
8678
let description = preprocess_description(&description.get_description_text());
8779
if !description.is_empty() {
8880
if !description_text.is_empty() {
@@ -130,8 +122,7 @@ pub fn analyze_enum(analyzer: &mut DocAnalyzer, tag: LuaDocTagEnum) -> Option<()
130122
enum_decl.add_enum_base(base_type);
131123
}
132124

133-
let description = tag.get_description();
134-
add_description_for_type_decl(analyzer, &enum_decl_id, description);
125+
add_description_for_type_decl(analyzer, &enum_decl_id, tag.get_descriptions());
135126

136127
bind_def_type(analyzer, LuaType::Def(enum_decl_id.clone()));
137128

@@ -182,8 +173,7 @@ pub fn analyze_alias(analyzer: &mut DocAnalyzer, tag: LuaDocTagAlias) -> Option<
182173

183174
alias.add_alias_origin(origin_type);
184175

185-
let description = tag.get_description();
186-
add_description_for_type_decl(analyzer, &alias_decl_id, description);
176+
add_description_for_type_decl(analyzer, &alias_decl_id, tag.get_descriptions());
187177

188178
Some(())
189179
}

crates/emmylua_parser/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "emmylua_parser"
3-
version = "0.10.8"
3+
version = "0.11.0"
44
edition = "2021"
55
authors = ["CppCXY"]
66
description = "A parser for EmmyLua and luals"

0 commit comments

Comments
 (0)