Add doc_comments to param decl
parent
85575704a4
commit
efa751c339
|
@ -940,6 +940,7 @@ pub const Node = struct {
|
||||||
|
|
||||||
pub const ParamDecl = struct {
|
pub const ParamDecl = struct {
|
||||||
base: Node,
|
base: Node,
|
||||||
|
doc_comments: ?*DocComment,
|
||||||
comptime_token: ?TokenIndex,
|
comptime_token: ?TokenIndex,
|
||||||
noalias_token: ?TokenIndex,
|
noalias_token: ?TokenIndex,
|
||||||
name_token: ?TokenIndex,
|
name_token: ?TokenIndex,
|
||||||
|
|
|
@ -854,12 +854,14 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree {
|
||||||
},
|
},
|
||||||
|
|
||||||
State.ParamDecl => |fn_proto| {
|
State.ParamDecl => |fn_proto| {
|
||||||
|
const comments = try eatDocComments(arena, &tok_it, &tree);
|
||||||
if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| {
|
if (eatToken(&tok_it, &tree, Token.Id.RParen)) |_| {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const param_decl = try arena.create(ast.Node.ParamDecl);
|
const param_decl = try arena.create(ast.Node.ParamDecl);
|
||||||
param_decl.* = ast.Node.ParamDecl{
|
param_decl.* = ast.Node.ParamDecl{
|
||||||
.base = ast.Node{ .id = ast.Node.Id.ParamDecl },
|
.base = ast.Node{ .id = ast.Node.Id.ParamDecl },
|
||||||
|
.doc_comments = comments,
|
||||||
.comptime_token = null,
|
.comptime_token = null,
|
||||||
.noalias_token = null,
|
.noalias_token = null,
|
||||||
.name_token = null,
|
.name_token = null,
|
||||||
|
|
|
@ -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" {
|
test "zig fmt: preserve space between async fn definitions" {
|
||||||
try testCanonical(
|
try testCanonical(
|
||||||
\\async fn a() void {}
|
\\async fn a() void {}
|
||||||
|
|
|
@ -1137,7 +1137,7 @@ fn renderExpression(
|
||||||
var it = fn_proto.params.iterator(0);
|
var it = fn_proto.params.iterator(0);
|
||||||
while (it.next()) |param_decl_node| {
|
while (it.next()) |param_decl_node| {
|
||||||
try stream.writeByteNTimes(' ', new_indent);
|
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);
|
try stream.writeByteNTimes(' ', indent);
|
||||||
}
|
}
|
||||||
|
@ -1779,6 +1779,8 @@ fn renderParamDecl(
|
||||||
) (@typeOf(stream).Child.Error || Error)!void {
|
) (@typeOf(stream).Child.Error || Error)!void {
|
||||||
const param_decl = @fieldParentPtr(ast.Node.ParamDecl, "base", base);
|
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| {
|
if (param_decl.comptime_token) |comptime_token| {
|
||||||
try renderToken(tree, stream, comptime_token, indent, start_col, Space.Space);
|
try renderToken(tree, stream, comptime_token, indent, start_col, Space.Space);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue