File tree Expand file tree Collapse file tree
emmylua_code_analysis/src/compilation/analyzer/doc
emmylua_ls/src/handlers/test
emmylua_parser/src/syntax/node/doc Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -93,12 +93,12 @@ impl<'a> DocAnalyzer<'a> {
9393}
9494
9595pub 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 }
Original file line number Diff line number Diff 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\n function test()\n ```\n \n ---\n \n 测试" . to_string( ) ,
501+ } ,
502+ ) ) ;
503+ }
481504}
Original file line number Diff line number Diff 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+
4861impl 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 }
You can’t perform that action at this time.
0 commit comments