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" {...@@ -1435,27 +1435,27 @@ test "zig fmt: if condition has line break but must not wrap" {
1435 );1435 );
1436}1436}
14371437
1438//test "zig fmt: if condition has line break but must not wrap" {1438test "zig fmt: if condition has line break but must not wrap (no fn call comma)" {
1439// try testCanonical(1439 try testCanonical(
1440// \\comptime {1440 \\comptime {
1441// \\ if (self.user_input_options.put(name, UserInputOption{1441 \\ if (self.user_input_options.put(name, UserInputOption{
1442// \\ .name = name,1442 \\ .name = name,
1443// \\ .used = false,1443 \\ .used = false,
1444// \\ }) catch unreachable) |*prev_value| {1444 \\ }) catch unreachable) |*prev_value| {
1445// \\ foo();1445 \\ foo();
1446// \\ bar();1446 \\ bar();
1447// \\ }1447 \\ }
1448// \\ if (put(1448 \\ if (put(
1449// \\ a,1449 \\ a,
1450// \\ b,1450 \\ b,
1451// \\ )) {1451 \\ )) {
1452// \\ foo();1452 \\ foo();
1453// \\ }1453 \\ }
1454// \\}1454 \\}
1455// \\1455 \\
1456// );1456 );
1457//}1457}
1458//1458
1459//test "zig fmt: function call with multiline argument" {1459//test "zig fmt: function call with multiline argument" {
1460// try testCanonical(1460// try testCanonical(
1461// \\comptime {1461// \\comptime {
lib/std/zig/render.zig+13-15
...@@ -1903,28 +1903,23 @@ fn renderCall(...@@ -1903,28 +1903,23 @@ fn renderCall(
1903 return renderToken(ais, tree, after_last_param_tok + 1, space); // )1903 return renderToken(ais, tree, after_last_param_tok + 1, space); // )
1904 }1904 }
19051905
1906 ais.pushIndentNextLine();
1907 try renderToken(ais, tree, lparen, .none); // (1906 try renderToken(ais, tree, lparen, .none); // (
19081907
1909 for (params) |param_node, i| {1908 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 }
1910 try renderExpression(ais, tree, param_node, .none);1913 try renderExpression(ais, tree, param_node, .none);
19111914
1912 if (i + 1 < params.len) {1915 if (i + 1 < params.len) {
1913 const comma = tree.lastToken(param_node) + 1;1916 const comma = tree.lastToken(param_node) + 1;
1914 const this_multiline_string = node_tags[param_node] == .multiline_string_literal;
1915 const next_multiline_string = node_tags[params[i + 1]] == .multiline_string_literal;1917 const next_multiline_string = node_tags[params[i + 1]] == .multiline_string_literal;
1916 const comma_space: Space = if (next_multiline_string) .none else .space;1918 const comma_space: Space = if (next_multiline_string) .none else .space;
1917 if (this_multiline_string) {1919 try renderToken(ais, tree, comma, comma_space);
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 }
1924 }1920 }
1925 }1921 }
19261922
1927 ais.popIndent();
1928 return renderToken(ais, tree, after_last_param_tok, space); // )1923 return renderToken(ais, tree, after_last_param_tok, space); // )
1929}1924}
19301925
...@@ -2234,9 +2229,12 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type {...@@ -2234,9 +2229,12 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type {
2234 indent_count: usize = 0,2229 indent_count: usize = 0,
2235 indent_delta: usize,2230 indent_delta: usize,
2236 current_line_empty: bool = true,2231 current_line_empty: bool = true,
2237 indent_one_shot_count: usize = 0, // automatically popped when applied2232 /// automatically popped when applied
2238 applied_indent: usize = 0, // the most recently applied indent2233 indent_one_shot_count: usize = 0,
2239 indent_next_line: usize = 0, // not used until the next line2234 /// the most recently applied indent
2235 applied_indent: usize = 0,
2236 /// not used until the next line
2237 indent_next_line: usize = 0,
22402238
2241 pub fn writer(self: *Self) Writer {2239 pub fn writer(self: *Self) Writer {
2242 return .{ .context = self };2240 return .{ .context = self };
...@@ -2291,9 +2289,9 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type {...@@ -2291,9 +2289,9 @@ fn AutoIndentingStream(comptime UnderlyingWriter: type) type {
2291 }2289 }
22922290
2293 /// Push default indentation2291 /// 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.
2294 pub fn pushIndent(self: *Self) void {2294 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.
2297 self.indent_count += 1;2295 self.indent_count += 1;
2298 }2296 }
22992297