diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-02-22 17:34:30 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-02-22 17:34:30 -0700 |
| commit | 20cfa0b5b62bf712d5aac882f7fde9b8e8cacae3 (patch) | |
| tree | e8d2e4f8055ea86af9788563b5778dfd43117bfe /lib/std | |
| parent | ec987a7a4652a0dbbd214e0252f35214532a9493 (diff) | |
| download | zig-20cfa0b5b62bf712d5aac882f7fde9b8e8cacae3.tar.gz zig-20cfa0b5b62bf712d5aac882f7fde9b8e8cacae3.zip | |
zig fmt: if condition has line break, no fn call comma
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/zig/parser_test.zig | 42 | ||||
| -rw-r--r-- | lib/std/zig/render.zig | 28 |
2 files changed, 34 insertions, 36 deletions
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index 0df9a16bc2..f7197e3853 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -1435,27 +1435,27 @@ test "zig fmt: if condition has line break but must not wrap" { ); } -//test "zig fmt: if condition has line break but must not wrap" { -// try testCanonical( -// \\comptime { -// \\ if (self.user_input_options.put(name, UserInputOption{ -// \\ .name = name, -// \\ .used = false, -// \\ }) catch unreachable) |*prev_value| { -// \\ foo(); -// \\ bar(); -// \\ } -// \\ if (put( -// \\ a, -// \\ b, -// \\ )) { -// \\ foo(); -// \\ } -// \\} -// \\ -// ); -//} -// +test "zig fmt: if condition has line break but must not wrap (no fn call comma)" { + try testCanonical( + \\comptime { + \\ if (self.user_input_options.put(name, UserInputOption{ + \\ .name = name, + \\ .used = false, + \\ }) catch unreachable) |*prev_value| { + \\ foo(); + \\ bar(); + \\ } + \\ if (put( + \\ a, + \\ b, + \\ )) { + \\ foo(); + \\ } + \\} + \\ + ); +} + //test "zig fmt: function call with multiline argument" { // try testCanonical( // \\comptime { diff --git a/lib/std/zig/render.zig b/lib/std/zig/render.zig index a3974d7204..cd48013b42 100644 --- a/lib/std/zig/render.zig +++ b/lib/std/zig/render.zig @@ -1903,28 +1903,23 @@ fn renderCall( return renderToken(ais, tree, after_last_param_tok + 1, space); // ) } - ais.pushIndentNextLine(); try renderToken(ais, tree, lparen, .none); // ( for (params) |param_node, i| { + const this_multiline_string = node_tags[param_node] == .multiline_string_literal; + if (this_multiline_string) { + ais.pushIndentOneShot(); + } try renderExpression(ais, tree, param_node, .none); if (i + 1 < params.len) { const comma = tree.lastToken(param_node) + 1; - const this_multiline_string = node_tags[param_node] == .multiline_string_literal; const next_multiline_string = node_tags[params[i + 1]] == .multiline_string_literal; const comma_space: Space = if (next_multiline_string) .none else .space; - if (this_multiline_string) { - ais.popIndent(); - try renderToken(ais, tree, comma, comma_space); - ais.pushIndent(); - } else { - try renderToken(ais, tree, comma, comma_space); - } + try renderToken(ais, tree, comma, comma_space); } } - ais.popIndent(); return renderToken(ais, tree, after_last_param_tok, space); // ) } @@ -2234,9 +2229,12 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type { indent_count: usize = 0, indent_delta: usize, current_line_empty: bool = true, - indent_one_shot_count: usize = 0, // automatically popped when applied - applied_indent: usize = 0, // the most recently applied indent - indent_next_line: usize = 0, // not used until the next line + /// automatically popped when applied + indent_one_shot_count: usize = 0, + /// the most recently applied indent + applied_indent: usize = 0, + /// not used until the next line + indent_next_line: usize = 0, pub fn writer(self: *Self) Writer { return .{ .context = self }; @@ -2291,9 +2289,9 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type { } /// Push default indentation + /// Doesn't actually write any indentation. + /// Just primes the stream to be able to write the correct indentation if it needs to. pub fn pushIndent(self: *Self) void { - // Doesn't actually write any indentation. - // Just primes the stream to be able to write the correct indentation if it needs to. self.indent_count += 1; } |
