fmt: keep trailing comments after fn header decl (#13596)
parent
83ea97b1a3
commit
d80f5165dd
|
@ -530,7 +530,8 @@ pub mut:
|
||||||
has_await bool // 'true' if this function uses JS.await
|
has_await bool // 'true' if this function uses JS.await
|
||||||
//
|
//
|
||||||
comments []Comment // comments *after* the header, but *before* `{`; used for InterfaceDecl
|
comments []Comment // comments *after* the header, but *before* `{`; used for InterfaceDecl
|
||||||
next_comments []Comment // coments that are one line after the decl; used for InterfaceDecl
|
end_comments []Comment // comments *after* header declarations. E.g.: `fn C.C_func(x int) int // Comment`
|
||||||
|
next_comments []Comment // comments that are one line after the decl; used for InterfaceDecl
|
||||||
//
|
//
|
||||||
source_file &File = 0
|
source_file &File = 0
|
||||||
scope &Scope
|
scope &Scope
|
||||||
|
|
|
@ -914,6 +914,26 @@ pub fn (mut f Fmt) enum_decl(node ast.EnumDecl) {
|
||||||
pub fn (mut f Fmt) fn_decl(node ast.FnDecl) {
|
pub fn (mut f Fmt) fn_decl(node ast.FnDecl) {
|
||||||
f.attrs(node.attrs)
|
f.attrs(node.attrs)
|
||||||
f.write(node.stringify(f.table, f.cur_mod, f.mod2alias)) // `Expr` instead of `ast.Expr` in mod ast
|
f.write(node.stringify(f.table, f.cur_mod, f.mod2alias)) // `Expr` instead of `ast.Expr` in mod ast
|
||||||
|
// Handle trailing comments after fn header declarations
|
||||||
|
if node.end_comments.len > 0 {
|
||||||
|
first_comment := node.end_comments[0]
|
||||||
|
if first_comment.text.contains('\n') {
|
||||||
|
f.writeln('\n')
|
||||||
|
} else {
|
||||||
|
f.write(' ')
|
||||||
|
}
|
||||||
|
f.comment(first_comment)
|
||||||
|
if node.end_comments.len > 1 {
|
||||||
|
f.writeln('\n')
|
||||||
|
comments := node.end_comments[1..]
|
||||||
|
for i, comment in comments {
|
||||||
|
f.comment(comment)
|
||||||
|
if i != comments.len - 1 {
|
||||||
|
f.writeln('\n')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
f.fn_body(node)
|
f.fn_body(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
fn C.Mix_LoadMUS1(file byteptr) voidptr // *Mix_Music
|
||||||
|
|
||||||
|
fn C.Mix_LoadMUS2(file byteptr) voidptr //*Mix_Music
|
||||||
|
|
||||||
|
fn C.Mix_LoadMUS3(file byteptr) voidptr // 1
|
||||||
|
|
||||||
|
// 2
|
||||||
|
|
||||||
|
// 3
|
||||||
|
|
||||||
|
// Loads music
|
||||||
|
fn C.Mix_LoadMUS4(file byteptr) voidptr
|
||||||
|
|
||||||
|
/*
|
||||||
|
Test
|
||||||
|
*/
|
|
@ -0,0 +1,9 @@
|
||||||
|
fn C.Mix_LoadMUS1(file byteptr) voidptr // *Mix_Music
|
||||||
|
|
||||||
|
fn C.Mix_LoadMUS2(file byteptr) voidptr /* *Mix_Music */
|
||||||
|
|
||||||
|
fn C.Mix_LoadMUS3(file byteptr) voidptr /* 1 */ /* 2 */ /* 3 */
|
||||||
|
|
||||||
|
// Loads music
|
||||||
|
fn C.Mix_LoadMUS4(file byteptr) voidptr /* Test
|
||||||
|
*/
|
|
@ -0,0 +1,5 @@
|
||||||
|
fn C.Mix_LoadMUS1(file byteptr) voidptr // Mix_Music
|
||||||
|
|
||||||
|
fn C.Mix_LoadMUS2(file byteptr) voidptr // Mix_Music 2
|
||||||
|
|
||||||
|
// Comment
|
|
@ -527,6 +527,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
|
||||||
is_builtin: p.builtin_mod || p.mod in util.builtin_module_parts
|
is_builtin: p.builtin_mod || p.mod in util.builtin_module_parts
|
||||||
scope: p.scope
|
scope: p.scope
|
||||||
label_names: p.label_names
|
label_names: p.label_names
|
||||||
|
end_comments: p.eat_comments(same_line: true)
|
||||||
}
|
}
|
||||||
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