From dedb8f7e41bca00a189aca2c26ceb3a9ff9db874 Mon Sep 17 00:00:00 2001 From: Lukas Neubert Date: Wed, 2 Dec 2020 04:06:20 +0100 Subject: [PATCH] fmt: smarter wrap of orm lines (#7070) --- vlib/v/fmt/fmt.v | 5 +++-- vlib/v/fmt/tests/orm_keep.vv | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index a469c1402d..98b37a0fe1 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -465,6 +465,7 @@ pub fn (mut f Fmt) stmt(node ast.Stmt) { } else { f.write(' ') } + f.wrap_long_line(2, true) } f.write('where ') f.expr(node.where_expr) @@ -1110,8 +1111,8 @@ pub fn (mut f Fmt) expr(node ast.Expr) { } } -pub fn (mut f Fmt) wrap_long_line(penalty int, add_indent bool) bool { - if f.line_len <= max_len[penalty] { +pub fn (mut f Fmt) wrap_long_line(penalty_idx int, add_indent bool) bool { + if f.line_len <= max_len[penalty_idx] { return false } if f.out.buf[f.out.buf.len - 1] == ` ` { diff --git a/vlib/v/fmt/tests/orm_keep.vv b/vlib/v/fmt/tests/orm_keep.vv index ca4a56ebbe..28630c68bf 100644 --- a/vlib/v/fmt/tests/orm_keep.vv +++ b/vlib/v/fmt/tests/orm_keep.vv @@ -46,4 +46,8 @@ fn main() { sql db { delete from Customer where nr_orders == 10 && name == 'Bob' } + sql db { + update Customer set name = 'Queen Elizabeth II', age = 150, nr_orders = 42, country = 'Great Britain' + where id == 5 + } }