| ... | @@ -411,18 +411,18 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.I | ... | @@ -411,18 +411,18 @@ fn renderExpression(gpa: *Allocator, ais: *Ais, tree: ast.Tree, node: ast.Node.I |
| 411 | | 411 | |
| 412 | .struct_init_one, .struct_init_one_comma => { | 412 | .struct_init_one, .struct_init_one_comma => { |
| 413 | var fields: [1]ast.Node.Index = undefined; | 413 | var fields: [1]ast.Node.Index = undefined; |
| 414 | return renderStructInit(gpa, ais, tree, tree.structInitOne(&fields, node), space); | 414 | return renderStructInit(gpa, ais, tree, node, tree.structInitOne(&fields, node), space); |
| 415 | }, | 415 | }, |
| 416 | .struct_init_dot_two, .struct_init_dot_two_comma => { | 416 | .struct_init_dot_two, .struct_init_dot_two_comma => { |
| 417 | var fields: [2]ast.Node.Index = undefined; | 417 | var fields: [2]ast.Node.Index = undefined; |
| 418 | return renderStructInit(gpa, ais, tree, tree.structInitDotTwo(&fields, node), space); | 418 | return renderStructInit(gpa, ais, tree, node, tree.structInitDotTwo(&fields, node), space); |
| 419 | }, | 419 | }, |
| 420 | .struct_init_dot, | 420 | .struct_init_dot, |
| 421 | .struct_init_dot_comma, | 421 | .struct_init_dot_comma, |
| 422 | => return renderStructInit(gpa, ais, tree, tree.structInitDot(node), space), | 422 | => return renderStructInit(gpa, ais, tree, node, tree.structInitDot(node), space), |
| 423 | .struct_init, | 423 | .struct_init, |
| 424 | .struct_init_comma, | 424 | .struct_init_comma, |
| 425 | => return renderStructInit(gpa, ais, tree, tree.structInit(node), space), | 425 | => return renderStructInit(gpa, ais, tree, node, tree.structInit(node), space), |
| 426 | | 426 | |
| 427 | .call_one, .call_one_comma, .async_call_one, .async_call_one_comma => { | 427 | .call_one, .call_one_comma, .async_call_one, .async_call_one_comma => { |
| 428 | var params: [1]ast.Node.Index = undefined; | 428 | var params: [1]ast.Node.Index = undefined; |
| ... | @@ -1564,11 +1564,11 @@ fn renderBlock( | ... | @@ -1564,11 +1564,11 @@ fn renderBlock( |
| 1564 | try renderToken(ais, tree, tree.lastToken(block_node), space); // rbrace | 1564 | try renderToken(ais, tree, tree.lastToken(block_node), space); // rbrace |
| 1565 | } | 1565 | } |
| 1566 | | 1566 | |
| 1567 | // TODO: handle comments between fields | | |
| 1568 | fn renderStructInit( | 1567 | fn renderStructInit( |
| 1569 | gpa: *Allocator, | 1568 | gpa: *Allocator, |
| 1570 | ais: *Ais, | 1569 | ais: *Ais, |
| 1571 | tree: ast.Tree, | 1570 | tree: ast.Tree, |
| | 1571 | struct_node: ast.Node.Index, |
| 1572 | struct_init: ast.full.StructInit, | 1572 | struct_init: ast.full.StructInit, |
| 1573 | space: Space, | 1573 | space: Space, |
| 1574 | ) Error!void { | 1574 | ) Error!void { |
| ... | @@ -1582,9 +1582,10 @@ fn renderStructInit( | ... | @@ -1582,9 +1582,10 @@ fn renderStructInit( |
| 1582 | try renderToken(ais, tree, struct_init.ast.lbrace, .none); // lbrace | 1582 | try renderToken(ais, tree, struct_init.ast.lbrace, .none); // lbrace |
| 1583 | return renderToken(ais, tree, struct_init.ast.lbrace + 1, space); // rbrace | 1583 | return renderToken(ais, tree, struct_init.ast.lbrace + 1, space); // rbrace |
| 1584 | } | 1584 | } |
| 1585 | const last_field = struct_init.ast.fields[struct_init.ast.fields.len - 1]; | 1585 | |
| 1586 | const last_field_token = tree.lastToken(last_field); | 1586 | const rbrace = tree.lastToken(struct_node); |
| 1587 | if (token_tags[last_field_token + 1] == .comma) { | 1587 | const trailing_comma = token_tags[rbrace - 1] == .comma; |
| | 1588 | if (trailing_comma or hasComment(tree, struct_init.ast.lbrace, rbrace)) { |
| 1588 | // Render one field init per line. | 1589 | // Render one field init per line. |
| 1589 | ais.pushIndentNextLine(); | 1590 | ais.pushIndentNextLine(); |
| 1590 | try renderToken(ais, tree, struct_init.ast.lbrace, .newline); | 1591 | try renderToken(ais, tree, struct_init.ast.lbrace, .newline); |
| ... | @@ -1604,7 +1605,6 @@ fn renderStructInit( | ... | @@ -1604,7 +1605,6 @@ fn renderStructInit( |
| 1604 | } | 1605 | } |
| 1605 | | 1606 | |
| 1606 | ais.popIndent(); | 1607 | ais.popIndent(); |
| 1607 | return renderToken(ais, tree, last_field_token + 2, space); // rbrace | | |
| 1608 | } else { | 1608 | } else { |
| 1609 | // Render all on one line, no trailing comma. | 1609 | // Render all on one line, no trailing comma. |
| 1610 | try renderToken(ais, tree, struct_init.ast.lbrace, .space); | 1610 | try renderToken(ais, tree, struct_init.ast.lbrace, .space); |
| ... | @@ -1616,9 +1616,9 @@ fn renderStructInit( | ... | @@ -1616,9 +1616,9 @@ fn renderStructInit( |
| 1616 | try renderToken(ais, tree, init_token - 1, .space); // = | 1616 | try renderToken(ais, tree, init_token - 1, .space); // = |
| 1617 | try renderExpression(gpa, ais, tree, field_init, .comma_space); | 1617 | try renderExpression(gpa, ais, tree, field_init, .comma_space); |
| 1618 | } | 1618 | } |
| 1619 | | | |
| 1620 | return renderToken(ais, tree, last_field_token + 1, space); // rbrace | | |
| 1621 | } | 1619 | } |
| | 1620 | |
| | 1621 | return renderToken(ais, tree, rbrace, space); |
| 1622 | } | 1622 | } |
| 1623 | | 1623 | |
| 1624 | // TODO: handle comments between elements | 1624 | // TODO: handle comments between elements |