11mod builder;
2+ mod comment;
23mod expr;
34mod stats;
45
6+ use std:: collections:: HashSet ;
7+
58use builder:: { DocumentSymbolBuilder , LuaSymbol } ;
69use emmylua_code_analysis:: SemanticModel ;
7- use emmylua_parser:: { LuaAst , LuaAstNode , LuaChunk } ;
10+ use emmylua_parser:: { LuaAst , LuaAstNode , LuaChunk , LuaExpr , LuaTableExpr } ;
811use expr:: { build_closure_expr_symbol, build_table_symbol} ;
912use lsp_types:: {
1013 ClientCapabilities , DocumentSymbol , DocumentSymbolOptions , DocumentSymbolParams ,
@@ -20,6 +23,7 @@ use tokio_util::sync::CancellationToken;
2023use crate :: context:: ServerContextSnapshot ;
2124
2225use super :: RegisterCapabilities ;
26+ use comment:: build_doc_region_symbol;
2327
2428pub async fn on_document_symbol (
2529 context : ServerContextSnapshot ,
@@ -59,12 +63,25 @@ fn build_child_document_symbols(
5963 builder : & mut DocumentSymbolBuilder ,
6064 root : & LuaChunk ,
6165) -> Option < ( ) > {
66+ let mut skip_table_exprs: HashSet < LuaTableExpr > = HashSet :: new ( ) ;
67+
6268 for child in root. descendants :: < LuaAst > ( ) {
6369 match child {
6470 LuaAst :: LuaLocalStat ( local_stat) => {
71+ for value_expr in local_stat. get_value_exprs ( ) {
72+ if let LuaExpr :: TableExpr ( table_expr) = value_expr {
73+ skip_table_exprs. insert ( table_expr) ;
74+ }
75+ }
6576 build_local_stat_symbol ( builder, local_stat) ;
6677 }
6778 LuaAst :: LuaAssignStat ( assign_stat) => {
79+ let ( _, exprs) = assign_stat. get_var_and_expr_list ( ) ;
80+ for expr in exprs {
81+ if let LuaExpr :: TableExpr ( table_expr) = expr {
82+ skip_table_exprs. insert ( table_expr) ;
83+ }
84+ }
6885 build_assign_stat_symbol ( builder, assign_stat) ;
6986 }
7087 LuaAst :: LuaForStat ( for_stat) => {
@@ -83,7 +100,12 @@ fn build_child_document_symbols(
83100 build_closure_expr_symbol ( builder, closure) ;
84101 }
85102 LuaAst :: LuaTableExpr ( table) => {
86- build_table_symbol ( builder, table) ;
103+ if !skip_table_exprs. contains ( & table) {
104+ build_table_symbol ( builder, table) ;
105+ }
106+ }
107+ LuaAst :: LuaComment ( comment) => {
108+ build_doc_region_symbol ( builder, comment) ;
87109 }
88110 LuaAst :: LuaIfStat ( if_stat) => {
89111 build_if_stat_symbol ( builder, if_stat) ;
0 commit comments