aboutsummaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
Diffstat (limited to 'std')
-rw-r--r--std/zig/ast.zig1
-rw-r--r--std/zig/parse.zig2
-rw-r--r--std/zig/parser_test.zig20
-rw-r--r--std/zig/render.zig4
4 files changed, 26 insertions, 1 deletions
diff --git a/std/zig/ast.zig b/std/zig/ast.zig
index 7149d4b3e6..9aba59f77c 100644
--- a/std/zig/ast.zig
+++ b/std/zig/ast.zig
@@ -940,6 +940,7 @@ pub const Node = struct {
pub const ParamDecl = struct {
base: Node,
+ doc_comments: ?*DocComment,
comptime_token: ?TokenIndex,
noalias_token: ?TokenIndex,
name_token: ?TokenIndex,
diff --git a/std/zig/parse.zig b/std/zig/parse.zig
index 93d15975fb..5214a0575b 100644
--- a/std/zig/parse.zig
+++ b/std/zig/parse.zig
@@ -854,12 +854,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
},
State.ParamDecl => |fn_proto| {
+ const comments = try eatDocComments(arena, &tok_it, &tree);
if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| {
continue;
}
const param_decl = try arena.create(ast.Node.ParamDecl);
param_decl.* = ast.Node.ParamDecl{
.base = ast.Node{ .id = ast.Node.Id.ParamDecl },
+ .doc_comments = comments,
.comptime_token = null,
.noalias_token = null,
.name_token = null,
diff --git a/std/zig/parser_test.zig b/std/zig/parser_test.zig
index 3be6b88063..371795394d 100644
--- a/std/zig/parser_test.zig
+++ b/std/zig/parser_test.zig
@@ -75,6 +75,26 @@ test "zig fmt: correctly move doc comments on struct fields" {
);
}
+test "zig fmt: doc comments on param decl" {
+ try testCanonical(
+ \\pub const Allocator = struct {
+ \\ shrinkFn: fn (
+ \\ self: *Allocator,
+ \\ /// Guaranteed to be the same as what was returned from most recent call to
+ \\ /// `allocFn`, `reallocFn`, or `shrinkFn`.
+ \\ old_mem: []u8,
+ \\ /// Guaranteed to be the same as what was returned from most recent call to
+ \\ /// `allocFn`, `reallocFn`, or `shrinkFn`.
+ \\ old_alignment: u29,
+ \\ /// Guaranteed to be less than or equal to `old_mem.len`.
+ \\ new_byte_count: usize,
+ \\ /// Guaranteed to be less than or equal to `old_alignment`.
+ \\ new_alignment: u29,
+ \\ ) []u8,
+ \\};
+ );
+}
+
test "zig fmt: preserve space between async fn definitions" {
try testCanonical(
\\async fn a() void {}
diff --git a/std/zig/render.zig b/std/zig/render.zig
index 1179eaa419..f1b5982720 100644
--- a/std/zig/render.zig
+++ b/std/zig/render.zig
@@ -1137,7 +1137,7 @@ fn renderExpression(
var it = fn_proto.params.iterator(0);
while (it.next()) |param_decl_node| {
try stream.writeByteNTimes(' ', new_indent);
- try renderParamDecl(allocator, stream, tree, indent, start_col, param_decl_node.*, Space.Comma);
+ try renderParamDecl(allocator, stream, tree, new_indent, start_col, param_decl_node.*, Space.Comma);
}
try stream.writeByteNTimes(' ', indent);
}
@@ -1779,6 +1779,8 @@ fn renderParamDecl(
) (@typeOf(stream).Child.Error || Error)!void {
const param_decl = @fieldParentPtr(ast.Node.ParamDecl, "base", base);
+ try renderDocComments(tree, stream, param_decl, indent, start_col);
+
if (param_decl.comptime_token) |comptime_token| {
try renderToken(tree, stream, comptime_token, indent, start_col, Space.Space);
}