Skip to content

Commit ef944c1

Browse files
committed
support grammar ---@field (internal) name type
1 parent 1b8b030 commit ef944c1

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::Arc;
22

33
use emmylua_parser::{
44
LuaAstNode, LuaAstToken, LuaDocDescriptionOwner, LuaDocFieldKey, LuaDocTagField,
5-
LuaDocTagOperator, LuaDocType,
5+
LuaDocTagOperator, LuaDocType, VisibilityKind,
66
};
77

88
use crate::{
@@ -35,6 +35,8 @@ pub fn analyze_field(analyzer: &mut DocAnalyzer, tag: LuaDocTagField) -> Option<
3535
let owner_id = LuaMemberOwner::Type(current_type_id.clone());
3636
let visibility_kind = if let Some(visibility_token) = tag.get_visibility_token() {
3737
Some(visibility_token.get_visibility())
38+
} else if let Some(visibility) = get_visibility_from_field_attrib(&tag) {
39+
Some(visibility)
3840
} else {
3941
None
4042
};
@@ -186,3 +188,16 @@ pub fn analyze_operator(analyzer: &mut DocAnalyzer, tag: LuaDocTagOperator) -> O
186188

187189
Some(())
188190
}
191+
192+
fn get_visibility_from_field_attrib(tag: &LuaDocTagField) -> Option<VisibilityKind> {
193+
if let Some(attrib) = tag.get_attrib() {
194+
for token in attrib.get_attrib_tokens() {
195+
let visibility = VisibilityKind::to_visibility_kind(token.get_name_text());
196+
if visibility != VisibilityKind::None {
197+
return Some(visibility);
198+
}
199+
}
200+
}
201+
202+
None
203+
}

crates/emmylua_parser/src/syntax/node/doc/tag.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,10 @@ impl LuaDocTagField {
658658
pub fn get_visibility_token(&self) -> Option<LuaDocVisibilityToken> {
659659
self.token()
660660
}
661+
662+
pub fn get_attrib(&self) -> Option<LuaDocAttribute> {
663+
self.child()
664+
}
661665
}
662666

663667
#[derive(Debug, Clone, PartialEq, Eq, Hash)]

0 commit comments

Comments
 (0)