Skip to content

Commit f94d882

Browse files
committed
fix get_description
1 parent e422ea7 commit f94d882

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ impl<'a> DocAnalyzer<'a> {
9393
}
9494

9595
pub fn preprocess_description(mut description: &str, owner: Option<&LuaSemanticDeclId>) -> String {
96-
let has_remove_start_char = if let Some(owner) = owner {
96+
let need_remove_start_char = if let Some(owner) = owner {
9797
!matches!(owner, LuaSemanticDeclId::Signature(_))
9898
} else {
9999
true
100100
};
101-
if has_remove_start_char {
101+
if need_remove_start_char {
102102
if description.starts_with(['#', '@']) {
103103
description = description.trim_start_matches(|c| c == '#' || c == '@');
104104
}

crates/emmylua_ls/src/handlers/test/hover_function_test.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,27 @@ mod tests {
478478
},
479479
));
480480
}
481+
482+
#[test]
483+
fn test_annotation_search() {
484+
let mut ws = ProviderVirtualWorkspace::new();
485+
ws.def_file(
486+
"a.lua",
487+
r#"
488+
---@version 5.4
489+
---测试
490+
function test()
491+
end
492+
493+
"#,
494+
);
495+
assert!(ws.check_hover(
496+
r#"
497+
<??>test()
498+
"#,
499+
VirtualHoverResult {
500+
value: "```lua\nfunction test()\n```\n\n---\n\n测试".to_string(),
501+
},
502+
));
503+
}
481504
}

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ impl LuaAstNode for LuaComment {
4545
}
4646
}
4747

48+
/// 检查语法节点是否为附加性质的文档标签
49+
///
50+
/// 附加性质的标签不会阻止查找 DocDescription
51+
fn is_additive_doc_tag(kind: LuaSyntaxKind) -> bool {
52+
matches!(
53+
kind,
54+
LuaSyntaxKind::DocTagVisibility
55+
| LuaSyntaxKind::DocTagExport
56+
| LuaSyntaxKind::DocTagVersion
57+
| LuaSyntaxKind::DocTagNodiscard
58+
)
59+
}
60+
4861
impl LuaComment {
4962
pub fn get_owner(&self) -> Option<LuaAst> {
5063
if let Some(inline_node) = find_inline_node(&self.syntax) {
@@ -66,8 +79,11 @@ impl LuaComment {
6679
LuaKind::Syntax(LuaSyntaxKind::DocDescription) => {
6780
return LuaDocDescription::cast(child.into_node().unwrap());
6881
}
69-
LuaKind::Token(LuaTokenKind::TkDocStart) => {
70-
return None;
82+
LuaKind::Token(LuaTokenKind::TkDocStart) => {}
83+
LuaKind::Syntax(syntax_kind) => {
84+
if !is_additive_doc_tag(syntax_kind) {
85+
return None;
86+
}
7187
}
7288
_ => {}
7389
}

0 commit comments

Comments
 (0)