parser, fmt: fix the formatting of fn headers with inline comments (#14010)
parent
07207db998
commit
3e3b2e25db
|
@ -953,8 +953,11 @@ fn (mut f Fmt) fn_body(node ast.FnDecl) {
|
||||||
if node.language == .v {
|
if node.language == .v {
|
||||||
if !node.no_body {
|
if !node.no_body {
|
||||||
f.write(' {')
|
f.write(' {')
|
||||||
|
f.comments(node.comments, inline: true)
|
||||||
if node.stmts.len > 0 || node.pos.line_nr < node.pos.last_line {
|
if node.stmts.len > 0 || node.pos.line_nr < node.pos.last_line {
|
||||||
f.writeln('')
|
if node.comments.len == 0 {
|
||||||
|
f.writeln('')
|
||||||
|
}
|
||||||
f.stmts(node.stmts)
|
f.stmts(node.stmts)
|
||||||
}
|
}
|
||||||
f.write('}')
|
f.write('}')
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
fn main() { // main
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_hi() { // hi
|
||||||
|
println('hi')
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
fn /*main*/main() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fn // hi
|
||||||
|
print_hi(){println('hi')}
|
|
@ -182,6 +182,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||||
mut is_ctor_new := false
|
mut is_ctor_new := false
|
||||||
mut is_c2v_variadic := false
|
mut is_c2v_variadic := false
|
||||||
mut is_markused := false
|
mut is_markused := false
|
||||||
|
mut comments := []ast.Comment{}
|
||||||
for fna in p.attrs {
|
for fna in p.attrs {
|
||||||
match fna.name {
|
match fna.name {
|
||||||
'noreturn' { is_noreturn = true }
|
'noreturn' { is_noreturn = true }
|
||||||
|
@ -205,6 +206,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||||
p.next()
|
p.next()
|
||||||
}
|
}
|
||||||
p.check(.key_fn)
|
p.check(.key_fn)
|
||||||
|
comments << p.eat_comments()
|
||||||
p.open_scope()
|
p.open_scope()
|
||||||
// C. || JS.
|
// C. || JS.
|
||||||
mut language := ast.Language.v
|
mut language := ast.Language.v
|
||||||
|
@ -530,6 +532,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||||
scope: p.scope
|
scope: p.scope
|
||||||
label_names: p.label_names
|
label_names: p.label_names
|
||||||
end_comments: p.eat_comments(same_line: true)
|
end_comments: p.eat_comments(same_line: true)
|
||||||
|
comments: comments
|
||||||
}
|
}
|
||||||
if generic_names.len > 0 {
|
if generic_names.len > 0 {
|
||||||
p.table.register_fn_generic_types(fn_decl.fkey())
|
p.table.register_fn_generic_types(fn_decl.fkey())
|
||||||
|
|
Loading…
Reference in New Issue