fn resetLine(ais: *AutoIndentingStream) void ais: *AutoIndentingStream3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439 fn resetLine(ais: *AutoIndentingStream) void {
ais.current_line_empty = true;
if (ais.disable_indent_committing > 0) return;
if (ais.indent_stack.items.len > 0) {
// By default, we realize the most recent indentation scope.
var to_realize = ais.indent_stack.items.len - 1;
if (ais.indent_stack.items.len >= 2 and
ais.indent_stack.items[to_realize - 1].indent_type == .after_equals and
ais.indent_stack.items[to_realize - 1].realized and
ais.indent_stack.items[to_realize].indent_type == .binop)
{
// If we are in a .binop scope and our direct parent is .after_equals, don't indent.
// This ensures correct indentation in the below example:
//
// const foo =
// (x >= 'a' and x <= 'z') or //<-- we are here
// (x >= 'A' and x <= 'Z');
//
return;
}
if (ais.indent_stack.items[to_realize].indent_type == .field_access) {
// Only realize the top-most field_access in a chain.
while (to_realize > 0 and ais.indent_stack.items[to_realize - 1].indent_type == .field_access)
to_realize -= 1;
}
if (ais.indent_stack.items[to_realize].realized) return;
ais.indent_stack.items[to_realize].realized = true;
ais.indent_count += 1;
}
}