fmt: keep comments after assign on same line (#7269)
parent
2a731e1c8e
commit
25153490e1
|
@ -697,6 +697,7 @@ pub:
|
||||||
op token.Kind
|
op token.Kind
|
||||||
pos token.Position
|
pos token.Position
|
||||||
comments []Comment
|
comments []Comment
|
||||||
|
end_comments []Comment
|
||||||
pub mut:
|
pub mut:
|
||||||
left []Expr
|
left []Expr
|
||||||
left_types []table.Type
|
left_types []table.Type
|
||||||
|
|
|
@ -282,6 +282,7 @@ pub fn (mut f Fmt) stmt(node ast.Stmt) {
|
||||||
f.write(', ')
|
f.write(', ')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
f.comments(node.end_comments, has_nl: false, inline: true, level: .keep)
|
||||||
if !f.single_line_if {
|
if !f.single_line_if {
|
||||||
f.writeln('')
|
f.writeln('')
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@ fn main() {
|
||||||
// just to make it worse
|
// just to make it worse
|
||||||
b, c := a, 2
|
b, c := a, 2
|
||||||
d := c // and an extra one
|
d := c // and an extra one
|
||||||
|
e := c
|
||||||
|
// more comments = more good
|
||||||
// before arg comment
|
// before arg comment
|
||||||
// after arg comment
|
// after arg comment
|
||||||
println('this is a test')
|
println('this is a test')
|
||||||
|
|
|
@ -10,6 +10,8 @@ fn main() {
|
||||||
a := /* this is a comment */ 1
|
a := /* this is a comment */ 1
|
||||||
b, c := /* and another comment */ a, /* just to make it worse */ 2
|
b, c := /* and another comment */ a, /* just to make it worse */ 2
|
||||||
d := c // and an extra one
|
d := c // and an extra one
|
||||||
|
e := c
|
||||||
|
// more comments = more good
|
||||||
println(/* before arg comment */ 'this is a test' /* after arg comment */)
|
println(/* before arg comment */ 'this is a test' /* after arg comment */)
|
||||||
if /* before if expr */ true /* after if expr */ {
|
if /* before if expr */ true /* after if expr */ {
|
||||||
println('if')
|
println('if')
|
||||||
|
|
|
@ -27,4 +27,9 @@ fn main() {
|
||||||
_ := User{
|
_ := User{
|
||||||
// Just a comment
|
// Just a comment
|
||||||
}
|
}
|
||||||
|
a := 123 // comment after assign
|
||||||
|
b := 'foo' // also comment after assign
|
||||||
|
c := true
|
||||||
|
// between two assigns
|
||||||
|
d := false
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,7 @@ fn (mut p Parser) partial_assign_stmt(left []ast.Expr, left_comments []ast.Comme
|
||||||
mut comments := []ast.Comment{cap: left_comments.len + right_comments.len}
|
mut comments := []ast.Comment{cap: left_comments.len + right_comments.len}
|
||||||
comments << left_comments
|
comments << left_comments
|
||||||
comments << right_comments
|
comments << right_comments
|
||||||
|
end_comments := p.eat_line_end_comments()
|
||||||
mut has_cross_var := false
|
mut has_cross_var := false
|
||||||
if op == .decl_assign {
|
if op == .decl_assign {
|
||||||
// a, b := a + 1, b
|
// a, b := a + 1, b
|
||||||
|
@ -187,6 +188,7 @@ fn (mut p Parser) partial_assign_stmt(left []ast.Expr, left_comments []ast.Comme
|
||||||
left: left
|
left: left
|
||||||
right: right
|
right: right
|
||||||
comments: comments
|
comments: comments
|
||||||
|
end_comments: end_comments
|
||||||
pos: pos
|
pos: pos
|
||||||
has_cross_var: has_cross_var
|
has_cross_var: has_cross_var
|
||||||
is_simple: p.inside_for && p.tok.kind == .lcbr
|
is_simple: p.inside_for && p.tok.kind == .lcbr
|
||||||
|
|
Loading…
Reference in New Issue