From 8be9bdacd169c712ad940d7b9729331f71418c2c Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Tue, 24 Nov 2020 12:55:39 +0100 Subject: [PATCH] fmt: do not wrap real multiline comments into single line in arrays (#6923) --- vlib/v/fmt/fmt.v | 20 ++++++++------------ vlib/v/fmt/tests/array_init_keep.vv | 9 +++++++++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index e238a6329d..6882af7a15 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -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) { if !f.buffering { if f.indent > 0 && f.empty_line { @@ -1224,8 +1214,14 @@ struct CommentsOptions { pub fn (mut f Fmt) comment(node ast.Comment, options CommentsOptions) { if options.iembed { - x := node.text.replace('\n', ' ').trim_left('\x01') - f.write('/* $x */') + x := node.text.trim_left('\x01') + if x.contains('\n') { + f.writeln('/*') + f.writeln(x) + f.write('*/') + } else { + f.write('/* $x */') + } return } if !node.text.contains('\n') { diff --git a/vlib/v/fmt/tests/array_init_keep.vv b/vlib/v/fmt/tests/array_init_keep.vv index b4fa793d54..93518b1b48 100644 --- a/vlib/v/fmt/tests/array_init_keep.vv +++ b/vlib/v/fmt/tests/array_init_keep.vv @@ -6,4 +6,13 @@ fn main() { 2, /* test 2 */ ] + arr2 := [ + 'foo', + /* + 'bar', + 'baz', + 'spam', + */ + 'eggs', + ] }