diff --git a/cmd/tools/fast/fast.v b/cmd/tools/fast/fast.v
index 78f4d31890..2bf0c83aa9 100644
--- a/cmd/tools/fast/fast.v
+++ b/cmd/tools/fast/fast.v
@@ -54,7 +54,7 @@ fn main() {
date := time.unix(commit_date.int())
mut out := os.create('table.html') ?
// Place the new row on top
- table =
+ table =
'
$date.format() |
$commit |
diff --git a/cmd/tools/vdoc/html.v b/cmd/tools/vdoc/html.v
index 2f4fd4e914..bd516afeca 100644
--- a/cmd/tools/vdoc/html.v
+++ b/cmd/tools/vdoc/html.v
@@ -228,7 +228,7 @@ fn (vd VDoc) write_content(cn &doc.DocNode, d &doc.Doc, mut hw strings.Builder)
}
for child in cn.children {
child_file_path_name := child.file_path.replace('$base_dir/', '')
- child_src_link := get_src_link(vd.manifest.repo_url, child_file_path_name,
+ child_src_link := get_src_link(vd.manifest.repo_url, child_file_path_name,
child.pos.line_nr + 1)
hw.write_string(doc_node_html(child, child_src_link, false, cfg.include_examples,
d.table))
diff --git a/cmd/tools/vdoc/utils.v b/cmd/tools/vdoc/utils.v
index e459ffb11e..4b07373b51 100644
--- a/cmd/tools/vdoc/utils.v
+++ b/cmd/tools/vdoc/utils.v
@@ -204,7 +204,7 @@ fn color_highlight(code string, tb &ast.Table) string {
if (tok.lit in builtin || tb.known_type(tok.lit))
&& (next_tok.kind != .lpar || prev.kind !in [.key_fn, .rpar]) {
tok_typ = .builtin
- } else if
+ } else if
next_tok.kind in [.lcbr, .rpar, .eof, .comma, .pipe, .name, .rcbr, .assign, .key_pub, .key_mut, .pipe, .comma]
&& prev.kind in [.name, .amp, .rsbr, .key_type, .assign, .dot, .question, .rpar, .key_struct, .key_enum, .pipe, .key_interface]
&& (tok.lit[0].ascii_str().is_upper() || prev_prev.lit in ['C', 'JS']) {
diff --git a/cmd/tools/vfmt.v b/cmd/tools/vfmt.v
index ee05828a63..a9cde364b1 100644
--- a/cmd/tools/vfmt.v
+++ b/cmd/tools/vfmt.v
@@ -267,7 +267,7 @@ fn (foptions &FormatOptions) post_process_file(file string, formatted_file_path
}
fn (f FormatOptions) str() string {
- return
+ return
'FormatOptions{ is_l: $f.is_l, is_w: $f.is_w, is_diff: $f.is_diff, is_verbose: $f.is_verbose,' +
' is_all: $f.is_all, is_worker: $f.is_worker, is_debug: $f.is_debug, is_noerror: $f.is_noerror,' +
' is_verify: $f.is_verify" }'
diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v
index 1ccad7edca..9fb10be620 100644
--- a/vlib/v/fmt/fmt.v
+++ b/vlib/v/fmt/fmt.v
@@ -1928,19 +1928,24 @@ pub fn (mut f Fmt) wrap_infix(start_pos int, start_len int, ignore_paren bool) {
for i, c in conditions {
cnd := c.trim_space()
if f.line_len + cnd.len < fmt.max_len[penalties[i]] {
- if (i > 0 && i < conditions.len) || (ignore_paren && i == 0 && cnd[3] == `(`) {
+ if (i > 0 && i < conditions.len)
+ || (ignore_paren && i == 0 && cnd.len > 5 && cnd[3] == `(`) {
f.write(' ')
}
f.write(cnd)
} else {
+ is_paren_expr := (cnd[0] == `(` || (cnd.len > 5 && cnd[3] == `(`)) && cnd.ends_with(')')
+ final_len := ((f.indent + 1) * 4) + cnd.len
prev_len := f.line_len
prev_pos := f.out.len
+ if i == 0 && !is_paren_expr {
+ f.remove_new_line({})
+ }
f.writeln('')
f.indent++
f.write(cnd)
f.indent--
- if f.line_len > fmt.max_len.last() && (cnd[0] == `(` || cnd[3] == `(`)
- && cnd.ends_with(')') {
+ if final_len > fmt.max_len.last() && is_paren_expr {
f.wrap_infix(prev_pos, prev_len, true)
}
}
diff --git a/vlib/v/fmt/tests/infix_expr_expected.vv b/vlib/v/fmt/tests/infix_expr_expected.vv
index 9174abaca5..62a9f264a3 100644
--- a/vlib/v/fmt/tests/infix_expr_expected.vv
+++ b/vlib/v/fmt/tests/infix_expr_expected.vv
@@ -14,3 +14,9 @@ fn unwrap_grouped_conds() {
fields = fields.filter((it.typ in [string_type, int_type, bool_type]
|| c.table.types[int(it.typ)].kind == .struct_) && !it.attrs.contains('skip'))
}
+
+fn main() {
+ clean_struct_v_type_name =
+ clean_struct_v_type_name.replace('_Array', '_array').replace('_T_', '<').replace('_', ', ') +
+ '>'
+}
diff --git a/vlib/v/fmt/tests/infix_expr_input.vv b/vlib/v/fmt/tests/infix_expr_input.vv
index e48d0ad30b..7971a231ab 100644
--- a/vlib/v/fmt/tests/infix_expr_input.vv
+++ b/vlib/v/fmt/tests/infix_expr_input.vv
@@ -9,3 +9,7 @@ fn unwrap_grouped_conds() {
_ := (also_inside_parens || just_as_above || but_this_is_also_more || than_a_single_line_could_fit) && end_cond
fields = fields.filter((it.typ in [string_type, int_type, bool_type] || c.table.types[int(it.typ)].kind == .struct_) && !it.attrs.contains('skip'))
}
+
+fn main() {
+ clean_struct_v_type_name = clean_struct_v_type_name.replace('_Array', '_array').replace('_T_', '<').replace('_', ', ') + '>'
+}
diff --git a/vlib/v/fmt/tests/infix_expr_keep.vv b/vlib/v/fmt/tests/infix_expr_keep.vv
new file mode 100644
index 0000000000..479aa10fac
--- /dev/null
+++ b/vlib/v/fmt/tests/infix_expr_keep.vv
@@ -0,0 +1,4 @@
+fn infix_in_multi_assign() {
+ child_width, child_height = child.adj_width + child.margin(.left) + child.margin(.right),
+ child.adj_height + child.margin(.top) + child.margin(.bottom)
+}
diff --git a/vlib/v/gen/c/auto_str_methods.v b/vlib/v/gen/c/auto_str_methods.v
index 1d8453bd10..9c362cf3eb 100644
--- a/vlib/v/gen/c/auto_str_methods.v
+++ b/vlib/v/gen/c/auto_str_methods.v
@@ -474,7 +474,7 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name stri
if clean_struct_v_type_name.contains('_T_') {
// TODO: this is a bit hacky. styp shouldn't be even parsed with _T_
// use something different than g.typ for styp
- clean_struct_v_type_name =
+ clean_struct_v_type_name =
clean_struct_v_type_name.replace('_Array', '_array').replace('_T_', '<').replace('_', ', ') +
'>'
}