fmt: do not wrap real multiline comments into single line in arrays (#6923)

pull/6937/head
Lukas Neubert 2020-11-24 12:55:39 +01:00 committed by GitHub
parent aa90625819
commit 8be9bdacd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 12 deletions

View File

@ -85,16 +85,6 @@ pub fn (mut f Fmt) process_file_imports(file &ast.File) {
} }
} }
/*
fn (mut f Fmt) find_comment(line_nr int) {
for comment in f.file.comments {
if comment.line_nr == line_nr {
f.writeln('// FFF $comment.line_nr $comment.text')
return
}
}
}
*/
pub fn (mut f Fmt) write(s string) { pub fn (mut f Fmt) write(s string) {
if !f.buffering { if !f.buffering {
if f.indent > 0 && f.empty_line { if f.indent > 0 && f.empty_line {
@ -1224,8 +1214,14 @@ struct CommentsOptions {
pub fn (mut f Fmt) comment(node ast.Comment, options CommentsOptions) { pub fn (mut f Fmt) comment(node ast.Comment, options CommentsOptions) {
if options.iembed { if options.iembed {
x := node.text.replace('\n', ' ').trim_left('\x01') x := node.text.trim_left('\x01')
f.write('/* $x */') if x.contains('\n') {
f.writeln('/*')
f.writeln(x)
f.write('*/')
} else {
f.write('/* $x */')
}
return return
} }
if !node.text.contains('\n') { if !node.text.contains('\n') {

View File

@ -6,4 +6,13 @@ fn main() {
2, 2,
/* test 2 */ /* test 2 */
] ]
arr2 := [
'foo',
/*
'bar',
'baz',
'spam',
*/
'eggs',
]
} }