| author | |
| committer | |
| log | efa751c3390cab0b5742051e02809d2ccfc62cc8 |
| tree | 4140830be70a54a8e5df881daf7ca7c5fc1b5c6a |
| parent | 85575704a4c1939f25414bc585a72bd940e85ceb |
4 files changed, 26 insertions(+), 1 deletions(-)
std/zig/ast.zig+1| ... | @@ -940,6 +940,7 @@ pub const Node = struct { | ... | @@ -940,6 +940,7 @@ pub const Node = struct { |
| 940 | 940 | ||
| 941 | pub const ParamDecl = struct { | 941 | pub const ParamDecl = struct { |
| 942 | base: Node, | 942 | base: Node, |
| 943 | doc_comments: ?*DocComment, | ||
| 943 | comptime_token: ?TokenIndex, | 944 | comptime_token: ?TokenIndex, |
| 944 | noalias_token: ?TokenIndex, | 945 | noalias_token: ?TokenIndex, |
| 945 | name_token: ?TokenIndex, | 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,12 +854,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 854 | }, | 854 | }, |
| 855 | 855 | ||
| 856 | State.ParamDecl => |fn_proto| { | 856 | State.ParamDecl => |fn_proto| { |
| 857 | const comments = try eatDocComments(arena, &tok_it, &tree); | ||
| 857 | if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| { | 858 | if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| { |
| 858 | continue; | 859 | continue; |
| 859 | } | 860 | } |
| 860 | const param_decl = try arena.create(ast.Node.ParamDecl); | 861 | const param_decl = try arena.create(ast.Node.ParamDecl); |
| 861 | param_decl.* = ast.Node.ParamDecl{ | 862 | param_decl.* = ast.Node.ParamDecl{ |
| 862 | .base = ast.Node{ .id = ast.Node.Id.ParamDecl }, | 863 | .base = ast.Node{ .id = ast.Node.Id.ParamDecl }, |
| 864 | .doc_comments = comments, | ||
| 863 | .comptime_token = null, | 865 | .comptime_token = null, |
| 864 | .noalias_token = null, | 866 | .noalias_token = null, |
| 865 | .name_token = null, | 867 | .name_token = null, |
std/zig/parser_test.zig+20| ... | @@ -75,6 +75,26 @@ test "zig fmt: correctly move doc comments on struct fields" { | ... | @@ -75,6 +75,26 @@ 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 | |||
| 78 | test "zig fmt: preserve space between async fn definitions" { | 98 | test "zig fmt: preserve space between async fn definitions" { |
| 79 | try testCanonical( | 99 | try testCanonical( |
| 80 | \\async fn a() void {} | 100 | \\async fn a() void {} |
std/zig/render.zig+3-1| ... | @@ -1137,7 +1137,7 @@ fn renderExpression( | ... | @@ -1137,7 +1137,7 @@ fn renderExpression( |
| 1137 | var it = fn_proto.params.iterator(0); | 1137 | var it = fn_proto.params.iterator(0); |
| 1138 | while (it.next()) |param_decl_node| { | 1138 | while (it.next()) |param_decl_node| { |
| 1139 | try stream.writeByteNTimes(' ', new_indent); | 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 | try stream.writeByteNTimes(' ', indent); | 1142 | try stream.writeByteNTimes(' ', indent); |
| 1143 | } | 1143 | } |
| ... | @@ -1779,6 +1779,8 @@ fn renderParamDecl( | ... | @@ -1779,6 +1779,8 @@ fn renderParamDecl( |
| 1779 | ) (@typeOf(stream).Child.Error || Error)!void { | 1779 | ) (@typeOf(stream).Child.Error || Error)!void { |
| 1780 | const param_decl = @fieldParentPtr(ast.Node.ParamDecl, "base", base); | 1780 | const param_decl = @fieldParentPtr(ast.Node.ParamDecl, "base", base); |
| 1781 | 1781 | ||
| 1782 | try renderDocComments(tree, stream, param_decl, indent, start_col); | ||
| 1783 | |||
| 1782 | if (param_decl.comptime_token) |comptime_token| { | 1784 | if (param_decl.comptime_token) |comptime_token| { |
| 1783 | try renderToken(tree, stream, comptime_token, indent, start_col, Space.Space); | 1785 | try renderToken(tree, stream, comptime_token, indent, start_col, Space.Space); |
| 1784 | } | 1786 | } |