|
1 | 1 | use crate::config::LuaFormatConfig; |
2 | 2 | use crate::ir::{self, DocIR}; |
3 | 3 | use emmylua_parser::{ |
4 | | - BinaryOperator, LuaAstNode, LuaChunk, LuaKind, LuaSyntaxId, LuaSyntaxKind, LuaSyntaxToken, |
5 | | - LuaTokenKind, |
| 4 | + BinaryOperator, LuaAstNode, LuaChunk, LuaKind, LuaOpKind, LuaSyntaxId, LuaSyntaxKind, |
| 5 | + LuaSyntaxToken, LuaTokenKind, |
6 | 6 | }; |
7 | 7 | use smol_str::SmolStr; |
8 | 8 |
|
@@ -234,10 +234,14 @@ fn analyze_token_spacing(ctx: &FormatContext, spacing: &mut SpacingModel, token: |
234 | 234 | | LuaTokenKind::TkElse |
235 | 235 | | LuaTokenKind::TkThen |
236 | 236 | | LuaTokenKind::TkUntil |
237 | | - | LuaTokenKind::TkIn |
238 | | - | LuaTokenKind::TkNot => { |
| 237 | + | LuaTokenKind::TkNot |
| 238 | + | LuaTokenKind::TkIn => { |
239 | 239 | apply_space_rule(spacing, syntax_id, SpaceRule::Space); |
240 | 240 | } |
| 241 | + LuaTokenKind::TkToggle => { |
| 242 | + spacing.add_token_left_expected(syntax_id, TokenSpacingExpected::Space(1)); |
| 243 | + spacing.add_token_right_expected(syntax_id, TokenSpacingExpected::Space(0)); |
| 244 | + } |
241 | 245 | LuaTokenKind::TkDocQuestion => { |
242 | 246 | spacing.add_token_left_expected(syntax_id, TokenSpacingExpected::Space(0)); |
243 | 247 | spacing.add_token_right_expected(syntax_id, TokenSpacingExpected::Space(1)); |
@@ -434,31 +438,7 @@ fn comment_start_looks_like_long_comment_prefix(token: &LuaSyntaxToken) -> bool |
434 | 438 | } |
435 | 439 |
|
436 | 440 | fn binary_space_rule_for_token(ctx: &FormatContext, token: &LuaSyntaxToken) -> Option<SpaceRule> { |
437 | | - let op = match token.kind().to_token() { |
438 | | - LuaTokenKind::TkPlus => BinaryOperator::OpAdd, |
439 | | - LuaTokenKind::TkMinus => BinaryOperator::OpSub, |
440 | | - LuaTokenKind::TkMul => BinaryOperator::OpMul, |
441 | | - LuaTokenKind::TkDiv => BinaryOperator::OpDiv, |
442 | | - LuaTokenKind::TkIDiv => BinaryOperator::OpIDiv, |
443 | | - LuaTokenKind::TkMod => BinaryOperator::OpMod, |
444 | | - LuaTokenKind::TkPow => BinaryOperator::OpPow, |
445 | | - LuaTokenKind::TkConcat => BinaryOperator::OpConcat, |
446 | | - LuaTokenKind::TkBitAnd => BinaryOperator::OpBAnd, |
447 | | - LuaTokenKind::TkBitOr => BinaryOperator::OpBOr, |
448 | | - LuaTokenKind::TkBitXor => BinaryOperator::OpBXor, |
449 | | - LuaTokenKind::TkShl => BinaryOperator::OpShl, |
450 | | - LuaTokenKind::TkShr => BinaryOperator::OpShr, |
451 | | - LuaTokenKind::TkEq => BinaryOperator::OpEq, |
452 | | - LuaTokenKind::TkGe => BinaryOperator::OpGe, |
453 | | - LuaTokenKind::TkGt => BinaryOperator::OpGt, |
454 | | - LuaTokenKind::TkLe => BinaryOperator::OpLe, |
455 | | - LuaTokenKind::TkLt => BinaryOperator::OpLt, |
456 | | - LuaTokenKind::TkNe => BinaryOperator::OpNe, |
457 | | - LuaTokenKind::TkAnd => BinaryOperator::OpAnd, |
458 | | - LuaTokenKind::TkOr => BinaryOperator::OpOr, |
459 | | - _ => return None, |
460 | | - }; |
461 | | - |
| 441 | + let op = LuaOpKind::to_binary_operator(token.kind().to_token()); |
462 | 442 | Some(space_around_binary_op(op, ctx.config)) |
463 | 443 | } |
464 | 444 |
|
|
0 commit comments