| ... | ... | @@ -1614,6 +1614,27 @@ fn renderBuiltinCall( |
| 1614 | 1614 | return renderParamList(r, builtin_token + 1, params, space); |
| 1615 | 1615 | } |
| 1616 | 1616 | |
| 1617 | fn isOneLineFnProto( |
| 1618 | tree: Ast, |
| 1619 | fn_proto: Ast.full.FnProto, |
| 1620 | lparen: Ast.TokenIndex, |
| 1621 | rparen: Ast.TokenIndex, |
| 1622 | ) bool { |
| 1623 | const trailing_comma = tree.tokenTag(rparen - 1) == .comma; |
| 1624 | if (trailing_comma or hasComment(tree, lparen, rparen)) |
| 1625 | return false; |
| 1626 | |
| 1627 | // Check that there are no doc comments |
| 1628 | var after_last_param = lparen + 1; |
| 1629 | for (fn_proto.ast.params) |expr| { |
| 1630 | // Looking before each param is insufficient since anytype is not included in `params` |
| 1631 | if (hasDocComment(tree, after_last_param, tree.firstToken(expr))) |
| 1632 | return false; |
| 1633 | after_last_param = tree.lastToken(expr) + 1; |
| 1634 | } |
| 1635 | return !hasDocComment(tree, after_last_param, rparen); |
| 1636 | } |
| 1637 | |
| 1617 | 1638 | fn renderFnProto(r: *Render, fn_proto: Ast.full.FnProto, space: Space) Error!void { |
| 1618 | 1639 | const tree = r.tree; |
| 1619 | 1640 | const ais = r.ais; |
| ... | ... | @@ -1674,8 +1695,7 @@ fn renderFnProto(r: *Render, fn_proto: Ast.full.FnProto, space: Space) Error!voi |
| 1674 | 1695 | |
| 1675 | 1696 | // The params list is a sparse set that does *not* include anytype or ... parameters. |
| 1676 | 1697 | |
| 1677 | | const trailing_comma = tree.tokenTag(rparen - 1) == .comma; |
| 1678 | | if (!trailing_comma and !hasComment(tree, lparen, rparen)) { |
| 1698 | if (isOneLineFnProto(tree, fn_proto, lparen, rparen)) { |
| 1679 | 1699 | // Render all on one line, no trailing comma. |
| 1680 | 1700 | try renderToken(r, lparen, .none); // ( |
| 1681 | 1701 | |
| ... | ... | @@ -1684,10 +1704,7 @@ fn renderFnProto(r: *Render, fn_proto: Ast.full.FnProto, space: Space) Error!voi |
| 1684 | 1704 | while (true) { |
| 1685 | 1705 | last_param_token += 1; |
| 1686 | 1706 | switch (tree.tokenTag(last_param_token)) { |
| 1687 | | .doc_comment => { |
| 1688 | | try renderToken(r, last_param_token, .newline); |
| 1689 | | continue; |
| 1690 | | }, |
| 1707 | .doc_comment => unreachable, |
| 1691 | 1708 | .ellipsis3 => { |
| 1692 | 1709 | try renderToken(r, last_param_token, .none); // ... |
| 1693 | 1710 | break; |