authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-22 17:34:30-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-22 17:34:30-07:00
log20cfa0b5b62bf712d5aac882f7fde9b8e8cacae3
treee8d2e4f8055ea86af9788563b5778dfd43117bfe
parentec987a7a4652a0dbbd214e0252f35214532a9493

zig fmt: if condition has line break, no fn call comma


2 files changed, 34 insertions(+), 36 deletions(-)

lib/std/zig/parser_test.zig+21-21
......@@ -1435,27 +1435,27 @@ test "zig fmt: if condition has line break but must not wrap" {
14351435 );
14361436}
14371437
1438//test "zig fmt: if condition has line break but must not wrap" {
1439// try testCanonical(
1440// \\comptime {
1441// \\ if (self.user_input_options.put(name, UserInputOption{
1442// \\ .name = name,
1443// \\ .used = false,
1444// \\ }) catch unreachable) |*prev_value| {
1445// \\ foo();
1446// \\ bar();
1447// \\ }
1448// \\ if (put(
1449// \\ a,
1450// \\ b,
1451// \\ )) {
1452// \\ foo();
1453// \\ }
1454// \\}
1455// \\
1456// );
1457//}
1458//
1438test "zig fmt: if condition has line break but must not wrap (no fn call comma)" {
1439 try testCanonical(
1440 \\comptime {
1441 \\ if (self.user_input_options.put(name, UserInputOption{
1442 \\ .name = name,
1443 \\ .used = false,
1444 \\ }) catch unreachable) |*prev_value| {
1445 \\ foo();
1446 \\ bar();
1447 \\ }
1448 \\ if (put(
1449 \\ a,
1450 \\ b,
1451 \\ )) {
1452 \\ foo();
1453 \\ }
1454 \\}
1455 \\
1456 );
1457}
1458
14591459//test "zig fmt: function call with multiline argument" {
14601460// try testCanonical(
14611461// \\comptime {
lib/std/zig/render.zig+13-15
......@@ -1903,28 +1903,23 @@ fn renderCall(
19031903 return renderToken(ais, tree, after_last_param_tok + 1, space); // )
19041904 }
19051905
1906 ais.pushIndentNextLine();
19071906 try renderToken(ais, tree, lparen, .none); // (
19081907
19091908 for (params) |param_node, i| {
1909 const this_multiline_string = node_tags[param_node] == .multiline_string_literal;
1910 if (this_multiline_string) {
1911 ais.pushIndentOneShot();
1912 }
19101913 try renderExpression(ais, tree, param_node, .none);
19111914
19121915 if (i + 1 < params.len) {
19131916 const comma = tree.lastToken(param_node) + 1;
1914 const this_multiline_string = node_tags[param_node] == .multiline_string_literal;
19151917 const next_multiline_string = node_tags[params[i + 1]] == .multiline_string_literal;
19161918 const comma_space: Space = if (next_multiline_string) .none else .space;
1917 if (this_multiline_string) {
1918 ais.popIndent();
1919 try renderToken(ais, tree, comma, comma_space);
1920 ais.pushIndent();
1921 } else {
1922 try renderToken(ais, tree, comma, comma_space);
1923 }
1919 try renderToken(ais, tree, comma, comma_space);
19241920 }
19251921 }
19261922
1927 ais.popIndent();
19281923 return renderToken(ais, tree, after_last_param_tok, space); // )
19291924}
19301925
......@@ -2234,9 +2229,12 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type {
22342229 indent_count: usize = 0,
22352230 indent_delta: usize,
22362231 current_line_empty: bool = true,
2237 indent_one_shot_count: usize = 0, // automatically popped when applied
2238 applied_indent: usize = 0, // the most recently applied indent
2239 indent_next_line: usize = 0, // not used until the next line
2232 /// automatically popped when applied
2233 indent_one_shot_count: usize = 0,
2234 /// the most recently applied indent
2235 applied_indent: usize = 0,
2236 /// not used until the next line
2237 indent_next_line: usize = 0,
22402238
22412239 pub fn writer(self: *Self) Writer {
22422240 return .{ .context = self };
......@@ -2291,9 +2289,9 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type {
22912289 }
22922290
22932291 /// Push default indentation
2292 /// Doesn't actually write any indentation.
2293 /// Just primes the stream to be able to write the correct indentation if it needs to.
22942294 pub fn pushIndent(self: *Self) void {
2295 // Doesn't actually write any indentation.
2296 // Just primes the stream to be able to write the correct indentation if it needs to.
22972295 self.indent_count += 1;
22982296 }
22992297