fmt: minor cleanups (#9090)
parent
7663f826e5
commit
28fc91acb7
|
@ -68,14 +68,13 @@ pub fn fmt(file ast.File, table &table.Table, pref &pref.Preferences, is_debug b
|
||||||
f.indent--
|
f.indent--
|
||||||
f.stmts(file.stmts)
|
f.stmts(file.stmts)
|
||||||
f.indent++
|
f.indent++
|
||||||
// for comment in file.comments { println('$comment.line_nr $comment.text') }
|
|
||||||
f.imports(f.file.imports) // now that we have all autoimports, handle them
|
f.imports(f.file.imports) // now that we have all autoimports, handle them
|
||||||
res := f.out.str().trim_space() + '\n'
|
res := f.out.str().trim_space() + '\n'
|
||||||
if res.len == 1 {
|
if res.len == 1 {
|
||||||
return f.out_imports.str().trim_space() + '\n'
|
return f.out_imports.str().trim_space() + '\n'
|
||||||
}
|
}
|
||||||
bounded_import_pos := util.imin(res.len, f.import_pos)
|
bounded_import_pos := util.imin(res.len, f.import_pos)
|
||||||
return res[..bounded_import_pos] + f.out_imports.str() + res[bounded_import_pos..] // + '\n'
|
return res[..bounded_import_pos] + f.out_imports.str() + res[bounded_import_pos..]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut f Fmt) process_file_imports(file &ast.File) {
|
pub fn (mut f Fmt) process_file_imports(file &ast.File) {
|
||||||
|
@ -1562,8 +1561,7 @@ pub fn (mut f Fmt) lock_expr(lex ast.LockExpr) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f.write(' {')
|
f.writeln(' {')
|
||||||
f.writeln('')
|
|
||||||
f.stmts(lex.stmts)
|
f.stmts(lex.stmts)
|
||||||
f.write('}')
|
f.write('}')
|
||||||
}
|
}
|
||||||
|
@ -1770,6 +1768,9 @@ fn (mut f Fmt) write_generic_if_require(node ast.CallExpr) {
|
||||||
|
|
||||||
pub fn (mut f Fmt) call_args(args []ast.CallArg) {
|
pub fn (mut f Fmt) call_args(args []ast.CallArg) {
|
||||||
f.single_line_fields = true
|
f.single_line_fields = true
|
||||||
|
defer {
|
||||||
|
f.single_line_fields = false
|
||||||
|
}
|
||||||
for i, arg in args {
|
for i, arg in args {
|
||||||
if arg.is_mut {
|
if arg.is_mut {
|
||||||
f.write(arg.share.str() + ' ')
|
f.write(arg.share.str() + ' ')
|
||||||
|
@ -1782,7 +1783,6 @@ pub fn (mut f Fmt) call_args(args []ast.CallArg) {
|
||||||
f.write(', ')
|
f.write(', ')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f.single_line_fields = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut f Fmt) call_expr(node ast.CallExpr) {
|
pub fn (mut f Fmt) call_expr(node ast.CallExpr) {
|
||||||
|
@ -1856,7 +1856,6 @@ pub fn (mut f Fmt) match_expr(it ast.MatchExpr) {
|
||||||
mut single_line := true
|
mut single_line := true
|
||||||
for branch in it.branches {
|
for branch in it.branches {
|
||||||
if branch.stmts.len > 1 || branch.pos.line_nr < branch.pos.last_line {
|
if branch.stmts.len > 1 || branch.pos.line_nr < branch.pos.last_line {
|
||||||
// println(branch)
|
|
||||||
single_line = false
|
single_line = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -1876,9 +1875,7 @@ pub fn (mut f Fmt) match_expr(it ast.MatchExpr) {
|
||||||
f.expr(expr)
|
f.expr(expr)
|
||||||
if j < branch.ecmnts.len && branch.ecmnts[j].len > 0 {
|
if j < branch.ecmnts.len && branch.ecmnts[j].len > 0 {
|
||||||
f.write(' ')
|
f.write(' ')
|
||||||
for cmnt in branch.ecmnts[j] {
|
f.comments(branch.ecmnts[j], iembed: true)
|
||||||
f.comment(cmnt, iembed: true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if j < branch.exprs.len - 1 {
|
if j < branch.exprs.len - 1 {
|
||||||
f.write(', ')
|
f.write(', ')
|
||||||
|
@ -1906,10 +1903,8 @@ pub fn (mut f Fmt) match_expr(it ast.MatchExpr) {
|
||||||
f.writeln('}')
|
f.writeln('}')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if branch.post_comments.len > 0 {
|
|
||||||
f.comments(branch.post_comments, inline: true)
|
f.comments(branch.post_comments, inline: true)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
f.indent--
|
f.indent--
|
||||||
f.write('}')
|
f.write('}')
|
||||||
f.it_name = ''
|
f.it_name = ''
|
||||||
|
@ -2285,8 +2280,7 @@ fn (mut f Fmt) global_decl(it ast.GlobalDecl) {
|
||||||
if single {
|
if single {
|
||||||
f.write('__global ( ')
|
f.write('__global ( ')
|
||||||
} else {
|
} else {
|
||||||
f.write('__global (')
|
f.writeln('__global (')
|
||||||
f.writeln('')
|
|
||||||
f.indent++
|
f.indent++
|
||||||
}
|
}
|
||||||
mut max := 0
|
mut max := 0
|
||||||
|
@ -2300,11 +2294,7 @@ fn (mut f Fmt) global_decl(it ast.GlobalDecl) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for field in it.fields {
|
for field in it.fields {
|
||||||
comments := field.comments
|
f.comments(field.comments, inline: true)
|
||||||
for comment in comments {
|
|
||||||
f.comment(comment, inline: true)
|
|
||||||
f.writeln('')
|
|
||||||
}
|
|
||||||
f.write('$field.name ')
|
f.write('$field.name ')
|
||||||
f.write(strings.repeat(` `, max - field.name.len))
|
f.write(strings.repeat(` `, max - field.name.len))
|
||||||
if field.has_expr {
|
if field.has_expr {
|
||||||
|
@ -2333,11 +2323,7 @@ fn (mut f Fmt) global_decl(it ast.GlobalDecl) {
|
||||||
pub fn (mut f Fmt) assign_stmt(node ast.AssignStmt) {
|
pub fn (mut f Fmt) assign_stmt(node ast.AssignStmt) {
|
||||||
f.comments(node.comments, {})
|
f.comments(node.comments, {})
|
||||||
for i, left in node.left {
|
for i, left in node.left {
|
||||||
if left is ast.Ident {
|
|
||||||
f.expr(left)
|
f.expr(left)
|
||||||
} else {
|
|
||||||
f.expr(left)
|
|
||||||
}
|
|
||||||
if i < node.left.len - 1 {
|
if i < node.left.len - 1 {
|
||||||
f.write(', ')
|
f.write(', ')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue