| ... | ... | @@ -1337,7 +1337,8 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: ast.Tree, fn_proto: ast.full. |
| 1337 | 1337 | |
| 1338 | 1338 | // The params list is a sparse set that does *not* include anytype or ... parameters. |
| 1339 | 1339 | |
| 1340 | | if (token_tags[rparen - 1] != .comma) { |
| 1340 | const trailing_comma = token_tags[rparen - 1] == .comma; |
| 1341 | if (!trailing_comma and !hasComment(tree, lparen, rparen)) { |
| 1341 | 1342 | // Render all on one line, no trailing comma. |
| 1342 | 1343 | try renderToken(ais, tree, lparen, .none); // ( |
| 1343 | 1344 | |
| ... | ... | @@ -1415,7 +1416,9 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: ast.Tree, fn_proto: ast.full. |
| 1415 | 1416 | continue; |
| 1416 | 1417 | }, |
| 1417 | 1418 | .r_paren => break, |
| 1418 | | else => unreachable, |
| 1419 | else => { |
| 1420 | std.debug.print("\n{}\n", .{token_tags[last_param_token]}); |
| 1421 | }, |
| 1419 | 1422 | } |
| 1420 | 1423 | if (token_tags[last_param_token] == .identifier) { |
| 1421 | 1424 | try renderToken(ais, tree, last_param_token, .none); // name |
| ... | ... | @@ -1430,7 +1433,8 @@ fn renderFnProto(gpa: *Allocator, ais: *Ais, tree: ast.Tree, fn_proto: ast.full. |
| 1430 | 1433 | const param = fn_proto.ast.params[param_i]; |
| 1431 | 1434 | param_i += 1; |
| 1432 | 1435 | try renderExpression(gpa, ais, tree, param, .comma); |
| 1433 | | last_param_token = tree.lastToken(param) + 1; |
| 1436 | last_param_token = tree.lastToken(param); |
| 1437 | if (token_tags[last_param_token + 1] == .comma) last_param_token += 1; |
| 1434 | 1438 | } |
| 1435 | 1439 | ais.popIndent(); |
| 1436 | 1440 | } |
| ... | ... | @@ -2171,6 +2175,19 @@ fn renderToken(ais: *Ais, tree: ast.Tree, token_index: ast.TokenIndex, space: Sp |
| 2171 | 2175 | } |
| 2172 | 2176 | } |
| 2173 | 2177 | |
| 2178 | /// Returns true if there exists a comment between the start of token |
| 2179 | /// `start_token` and the start of token `end_token`. This is used to determine |
| 2180 | /// if e.g. a fn_proto should be wrapped and have a trailing comma inserted |
| 2181 | /// even if there is none in the source. |
| 2182 | fn hasComment(tree: ast.Tree, start_token: ast.TokenIndex, end_token: ast.TokenIndex) bool { |
| 2183 | const token_starts = tree.tokens.items(.start); |
| 2184 | |
| 2185 | const start = token_starts[start_token]; |
| 2186 | const end = token_starts[end_token]; |
| 2187 | |
| 2188 | return mem.indexOf(u8, tree.source[start..end], "//") != null; |
| 2189 | } |
| 2190 | |
| 2174 | 2191 | /// Assumes that start is the first byte past the previous token and |
| 2175 | 2192 | /// that end is the last byte before the next token. |
| 2176 | 2193 | fn renderComments(ais: *Ais, tree: ast.Tree, start: usize, end: usize) Error!bool { |