Skip to content

Commit 66dd19d

Browse files
committed
<true type> else <false type> is better
1 parent 3c4e7c5 commit 66dd19d

File tree

6 files changed

+8
-10
lines changed

6 files changed

+8
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ pub fn analyze_return_cast(analyzer: &mut DocAnalyzer, tag: LuaDocTagReturnCast)
252252
let name = name_token.get_name_text();
253253

254254
let op_types: Vec<_> = tag.get_op_types().collect();
255-
let cast_op_type = op_types.get(0)?;
255+
let cast_op_type = op_types.first()?;
256256

257257
// Bind the true condition type
258258
if let Some(node_type) = cast_op_type.get_type() {

crates/emmylua_code_analysis/src/compilation/test/flow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ _2 = a[1]
13691369
---@class Monster: Creature
13701370
13711371
---@return boolean
1372-
---@return_cast creature Player, Monster
1372+
---@return_cast creature Player else Monster
13731373
local function isPlayer(creature)
13741374
return true
13751375
end
@@ -1407,7 +1407,7 @@ _2 = a[1]
14071407
local m = {}
14081408
14091409
---@return boolean
1410-
---@return_cast self Player, Monster
1410+
---@return_cast self Player else Monster
14111411
function m:isPlayer()
14121412
end
14131413

crates/emmylua_parser/src/grammar/doc/tag.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ fn parse_tag_return(p: &mut LuaDocParser) -> DocParseResult {
353353
}
354354

355355
// ---@return_cast <param name> <type>
356-
// ---@return_cast <param name> <true_type>, <false_type>
356+
// ---@return_cast <param name> <true_type> else <false_type>
357357
fn parse_tag_return_cast(p: &mut LuaDocParser) -> DocParseResult {
358358
p.set_state(LuaDocLexerState::Normal);
359359
let m = p.mark(LuaSyntaxKind::DocTagReturnCast);
@@ -362,8 +362,8 @@ fn parse_tag_return_cast(p: &mut LuaDocParser) -> DocParseResult {
362362

363363
parse_op_type(p)?;
364364

365-
// Allow optional second type after comma for false condition
366-
if p.current_token() == LuaTokenKind::TkComma {
365+
// Allow optional second type after 'else' for false condition
366+
if p.current_token() == LuaTokenKind::TkDocElse {
367367
p.bump();
368368
parse_op_type(p)?;
369369
}

crates/emmylua_parser/src/kind/lua_token_kind.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ pub enum LuaTokenKind {
143143
TkDocAs, // as
144144
TkDocIn, // in
145145
TkDocInfer, // infer
146+
TkDocElse, // else (for return_cast)
146147
TkDocContinue, // ---
147148
TkDocContinueOr, // ---| or ---|+ or ---|>
148149
TkDocDetail, // a description

crates/emmylua_parser/src/lexer/lua_doc_lexer.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ fn to_token_or_name(text: &str) -> LuaTokenKind {
638638
"as" => LuaTokenKind::TkDocAs,
639639
"and" => LuaTokenKind::TkAnd,
640640
"or" => LuaTokenKind::TkOr,
641+
"else" => LuaTokenKind::TkDocElse,
641642
_ => LuaTokenKind::TkName,
642643
}
643644
}

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,10 +1458,6 @@ impl LuaAstNode for LuaDocTagReturnCast {
14581458
impl LuaDocDescriptionOwner for LuaDocTagReturnCast {}
14591459

14601460
impl LuaDocTagReturnCast {
1461-
pub fn get_op_type(&self) -> Option<LuaDocOpType> {
1462-
self.child()
1463-
}
1464-
14651461
pub fn get_op_types(&self) -> LuaAstChildren<LuaDocOpType> {
14661462
self.children()
14671463
}

0 commit comments

Comments
 (0)