Skip to content

Commit e8e6337

Browse files
committed
parser support donot parse emmylua doc
1 parent 9e68ba8 commit e8e6337

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

crates/emmylua_code_analysis/src/config/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ impl Emmyrc {
8888
Some(node_cache),
8989
special_like,
9090
non_std_symbols,
91+
true,
9192
)
9293
}
9394

crates/emmylua_parser/src/parser/lua_parser.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ impl MarkerEventContainer for LuaParser<'_> {
4444
}
4545

4646
impl<'a> LuaParser<'a> {
47-
#[allow(unused)]
4847
pub fn parse(text: &'a str, config: ParserConfig) -> LuaSyntaxTree {
4948
let mut errors: Vec<LuaParseError> = Vec::new();
5049
let tokens = {
@@ -279,6 +278,16 @@ impl<'a> LuaParser<'a> {
279278
}
280279

281280
fn parse_comments(&mut self, comment_tokens: &[LuaTokenData]) {
281+
if !self.parse_config.support_emmylua_doc() {
282+
for token in comment_tokens {
283+
self.events.push(MarkEvent::EatToken {
284+
kind: token.kind,
285+
range: token.range,
286+
});
287+
}
288+
return;
289+
}
290+
282291
let mut trivia_token_start = comment_tokens.len();
283292
// Reverse iterate over comment_tokens, removing whitespace and end-of-line tokens
284293
for i in (0..comment_tokens.len()).rev() {

crates/emmylua_parser/src/parser/parser_config.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct ParserConfig<'cache> {
99
lexer_config: LexerConfig,
1010
node_cache: Option<&'cache mut NodeCache>,
1111
special_like: HashMap<String, SpecialFunction>,
12+
pub enable_emmylua_doc: bool,
1213
}
1314

1415
impl<'cache> ParserConfig<'cache> {
@@ -17,6 +18,7 @@ impl<'cache> ParserConfig<'cache> {
1718
node_cache: Option<&'cache mut NodeCache>,
1819
special_like: HashMap<String, SpecialFunction>,
1920
non_std_symbols: LuaNonStdSymbolSet,
21+
enable_emmylua_doc: bool,
2022
) -> Self {
2123
Self {
2224
level,
@@ -26,6 +28,7 @@ impl<'cache> ParserConfig<'cache> {
2628
},
2729
node_cache,
2830
special_like,
31+
enable_emmylua_doc,
2932
}
3033
}
3134

@@ -37,6 +40,10 @@ impl<'cache> ParserConfig<'cache> {
3740
self.level >= LuaLanguageLevel::Lua54
3841
}
3942

43+
pub fn support_emmylua_doc(&self) -> bool {
44+
self.enable_emmylua_doc
45+
}
46+
4047
pub fn node_cache(&mut self) -> Option<&mut NodeCache> {
4148
self.node_cache.as_deref_mut()
4249
}
@@ -64,6 +71,7 @@ impl<'cache> ParserConfig<'cache> {
6471
},
6572
node_cache: None,
6673
special_like: HashMap::new(),
74+
enable_emmylua_doc: true,
6775
}
6876
}
6977
}
@@ -78,6 +86,7 @@ impl Default for ParserConfig<'_> {
7886
},
7987
node_cache: None,
8088
special_like: HashMap::new(),
89+
enable_emmylua_doc: true,
8190
}
8291
}
8392
}

crates/emmylua_parser/src/syntax/tree/test.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ end
4343
None,
4444
HashMap::new(),
4545
LuaNonStdSymbolSet::new(),
46+
false,
4647
);
4748
let tree = LuaParser::parse(code, parse_config);
4849
assert_eq!(tree.get_errors().len(), 0);
@@ -86,4 +87,23 @@ local t
8687

8788
let _ = LuaParser::parse(code, ParserConfig::default());
8889
}
90+
91+
#[test]
92+
fn test_without_emmylua() {
93+
let code = r#"
94+
---@param key string
95+
---@return boolean
96+
local t
97+
"#;
98+
99+
let c = ParserConfig::new(
100+
LuaLanguageLevel::Lua54,
101+
None,
102+
HashMap::new(),
103+
LuaNonStdSymbolSet::new(),
104+
false,
105+
);
106+
let t = LuaParser::parse(code, c);
107+
println!("{:#?}", t.get_red_root());
108+
}
89109
}

0 commit comments

Comments
 (0)