| author | |
| committer | |
| log | 90a78866db5488ceae584e32287acb9f2461d945 |
| tree | 5ded749853638808e009c467b9ff770b4c2c5736 |
| parent | 5703ab1d0c68394f346673dc715c05813a6c4df1 |
| parent | b0d89cfe3fdd1139a194a1765460e11e6c34b45b |
| signature |
Add doc_comments to param decl4 files changed, 27 insertions(+), 1 deletions(-)
std/zig/ast.zig+1| ... | ... | @@ -940,6 +940,7 @@ pub const Node = struct { |
| 940 | 940 | |
| 941 | 941 | pub const ParamDecl = struct { |
| 942 | 942 | base: Node, |
| 943 | doc_comments: ?*DocComment, | |
| 943 | 944 | comptime_token: ?TokenIndex, |
| 944 | 945 | noalias_token: ?TokenIndex, |
| 945 | 946 | name_token: ?TokenIndex, |
std/zig/parse.zig+2| ... | ... | @@ -854,12 +854,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 854 | 854 | }, |
| 855 | 855 | |
| 856 | 856 | State.ParamDecl => |fn_proto| { |
| 857 | const comments = try eatDocComments(arena, &tok_it, &tree); | |
| 857 | 858 | if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| { |
| 858 | 859 | continue; |
| 859 | 860 | } |
| 860 | 861 | const param_decl = try arena.create(ast.Node.ParamDecl); |
| 861 | 862 | param_decl.* = ast.Node.ParamDecl{ |
| 862 | 863 | .base = ast.Node{ .id = ast.Node.Id.ParamDecl }, |
| 864 | .doc_comments = comments, | |
| 863 | 865 | .comptime_token = null, |
| 864 | 866 | .noalias_token = null, |
| 865 | 867 | .name_token = null, |
std/zig/parser_test.zig+21| ... | ... | @@ -75,6 +75,27 @@ test "zig fmt: correctly move doc comments on struct fields" { |
| 75 | 75 | ); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | test "zig fmt: doc comments on param decl" { | |
| 79 | try testCanonical( | |
| 80 | \\pub const Allocator = struct { | |
| 81 | \\ shrinkFn: fn ( | |
| 82 | \\ self: *Allocator, | |
| 83 | \\ /// Guaranteed to be the same as what was returned from most recent call to | |
| 84 | \\ /// `allocFn`, `reallocFn`, or `shrinkFn`. | |
| 85 | \\ old_mem: []u8, | |
| 86 | \\ /// Guaranteed to be the same as what was returned from most recent call to | |
| 87 | \\ /// `allocFn`, `reallocFn`, or `shrinkFn`. | |
| 88 | \\ old_alignment: u29, | |
| 89 | \\ /// Guaranteed to be less than or equal to `old_mem.len`. | |
| 90 | \\ new_byte_count: usize, | |
| 91 | \\ /// Guaranteed to be less than or equal to `old_alignment`. | |
| 92 | \\ new_alignment: u29, | |
| 93 | \\ ) []u8, | |
| 94 | \\}; | |
| 95 | \\ | |
| 96 | ); | |
| 97 | } | |
| 98 | ||
| 78 | 99 | test "zig fmt: preserve space between async fn definitions" { |
| 79 | 100 | try testCanonical( |
| 80 | 101 | \\async fn a() void {} |
std/zig/render.zig+3-1| ... | ... | @@ -1137,7 +1137,7 @@ fn renderExpression( |
| 1137 | 1137 | var it = fn_proto.params.iterator(0); |
| 1138 | 1138 | while (it.next()) |param_decl_node| { |
| 1139 | 1139 | try stream.writeByteNTimes(' ', new_indent); |
| 1140 | try renderParamDecl(allocator, stream, tree, indent, start_col, param_decl_node.*, Space.Comma); | |
| 1140 | try renderParamDecl(allocator, stream, tree, new_indent, start_col, param_decl_node.*, Space.Comma); | |
| 1141 | 1141 | } |
| 1142 | 1142 | try stream.writeByteNTimes(' ', indent); |
| 1143 | 1143 | } |
| ... | ... | @@ -1779,6 +1779,8 @@ fn renderParamDecl( |
| 1779 | 1779 | ) (@typeOf(stream).Child.Error || Error)!void { |
| 1780 | 1780 | const param_decl = @fieldParentPtr(ast.Node.ParamDecl, "base", base); |
| 1781 | 1781 | |
| 1782 | try renderDocComments(tree, stream, param_decl, indent, start_col); | |
| 1783 | ||
| 1782 | 1784 | if (param_decl.comptime_token) |comptime_token| { |
| 1783 | 1785 | try renderToken(tree, stream, comptime_token, indent, start_col, Space.Space); |
| 1784 | 1786 | } |