Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve indentation of attributes in patterns #2613

Merged
merged 6 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ profile. This started with version 0.26.0.
- Fix missing parentheses around a let in class expressions (#2599, @Julow)
- Fix formatting of paragraphs in lists in documentation (#2607, @Julow)
- Avoid unwanted space in references and links text in documentation (#2608, @Julow)
- \* Improve the indentation of attributes in patterns (#2613, @Julow)
- \* Avoid large indentation in patterns after `let%ext` (#2615, @Julow)

## 0.26.2 (2024-04-18)
Expand Down
11 changes: 9 additions & 2 deletions lib/Fmt_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1086,8 +1086,15 @@ and fmt_pattern_attributes c xpat k =
false
| _ -> true )
in
Params.parens_if parens_attr c.conf
(k $ fmt_attributes c ~pre:Space attrs)
let box =
match (xpat.ast.ppat_desc, c.conf.fmt_opts.sequence_style.v) with
| (Ppat_record _ | Ppat_array _ | Ppat_list _), `Terminator -> hovbox
| _ -> hvbox
in
box
(if parens_attr then 1 else 0)
(Params.parens_if parens_attr c.conf
(k $ fmt_attributes c ~pre:Space attrs) )

and fmt_pattern ?ext c ?pro ?parens ?(box = false)
({ctx= ctx0; ast= pat} as xpat) =
Expand Down
5 changes: 3 additions & 2 deletions test/passing/tests/attributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,15 @@ let pp f ({cf_interface; cf_is_objc_block; cf_virtual} [@warning "+9"]) = ()

let pp f
({cf_assign_last_arg; cf_injected_destructor; cf_interface}
[@warning "+9"] ) =
[@warning "+9"] ) =
()

let pp f
({ cf_assign_last_arg
; cf_injected_destructor
; cf_interface
; cf_is_objc_block } [@warning "+9"] ) =
; cf_is_objc_block }
[@warning "+9"] ) =
()

let _ = f ((* comments *) "c" [@attributes])
Expand Down
10 changes: 5 additions & 5 deletions test/passing/tests/js_source.ml.err
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Warning: tests/js_source.ml:9564 exceeds the margin
Warning: tests/js_source.ml:9668 exceeds the margin
Warning: tests/js_source.ml:9727 exceeds the margin
Warning: tests/js_source.ml:9810 exceeds the margin
Warning: tests/js_source.ml:10308 exceeds the margin
Warning: tests/js_source.ml:9563 exceeds the margin
Warning: tests/js_source.ml:9667 exceeds the margin
Warning: tests/js_source.ml:9726 exceeds the margin
Warning: tests/js_source.ml:9809 exceeds the margin
Warning: tests/js_source.ml:10307 exceeds the margin
3 changes: 1 addition & 2 deletions test/passing/tests/js_source.ml.ocp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ let () =
match[@foo] () with
| [%foo?
(* Pattern expressions *)
((lazy x)
[@foo])] -> ()
((lazy x) [@foo])] -> ()
| [%foo? ((exception x) [@foo])] -> ()]
;;

Expand Down
3 changes: 1 addition & 2 deletions test/passing/tests/js_source.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ let () =
match[@foo] () with
| [%foo?
(* Pattern expressions *)
((lazy x)
[@foo])] -> ()
((lazy x) [@foo])] -> ()
| [%foo? ((exception x) [@foo])] -> ()]
;;

Expand Down
3 changes: 2 additions & 1 deletion test/passing/tests/let_binding-deindent-fun.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ let copy from ~into : unit =
; pulse_summaries_count
; topl_reachable_calls
; timeouts
; timings } [@warning "+9"] ) =
; timings }
[@warning "+9"] ) =
()
in
()
Expand Down
3 changes: 2 additions & 1 deletion test/passing/tests/let_binding-in_indent.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ let copy from ~into : unit =
; pulse_summaries_count
; topl_reachable_calls
; timeouts
; timings } [@warning "+9"] ) =
; timings }
[@warning "+9"] ) =
()
in
()
Expand Down
3 changes: 2 additions & 1 deletion test/passing/tests/let_binding-indent.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ let copy from ~into : unit =
; pulse_summaries_count
; topl_reachable_calls
; timeouts
; timings } [@warning "+9"] ) =
; timings }
[@warning "+9"] ) =
()
in
()
Expand Down
3 changes: 2 additions & 1 deletion test/passing/tests/let_binding.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ let copy from ~into : unit =
; pulse_summaries_count
; topl_reachable_calls
; timeouts
; timings } [@warning "+9"] ) =
; timings }
[@warning "+9"] ) =
()
in
()
Expand Down
3 changes: 1 addition & 2 deletions test/passing/tests/list_normalized.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ let
(*a*)
[ x (*b*)
; (*c*)
(y
[@attr] )
(y [@attr])
(*d*)
(*e*) ] (*f*) =
e
8 changes: 8 additions & 0 deletions test/passing/tests/record-402.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@ let _ =
()
in
()

let foo
({ foooooooooooooooooooooo
; invalidation_trace
; access_trace
; must_be_valid_reason }
[@warning "+missing-record-field-pattern"] ) =
()
9 changes: 9 additions & 0 deletions test/passing/tests/record-default.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,12 @@ let _ =
()
in
()

let foo
({
foooooooooooooooooooooo;
invalidation_trace;
access_trace;
must_be_valid_reason;
} [@warning "+missing-record-field-pattern"]) =
()
8 changes: 8 additions & 0 deletions test/passing/tests/record-loose.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@ let _ =
()
in
()

let foo
({ foooooooooooooooooooooo
; invalidation_trace
; access_trace
; must_be_valid_reason }
[@warning "+missing-record-field-pattern"] ) =
()
8 changes: 8 additions & 0 deletions test/passing/tests/record-tight_decl.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@ let _ =
()
in
()

let foo
({ foooooooooooooooooooooo
; invalidation_trace
; access_trace
; must_be_valid_reason }
[@warning "+missing-record-field-pattern"] ) =
()
9 changes: 9 additions & 0 deletions test/passing/tests/record.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,12 @@ let _ =
()
in
()

let foo
({
foooooooooooooooooooooo;
invalidation_trace;
access_trace;
must_be_valid_reason;
} [@warning "+missing-record-field-pattern"]) =
()
8 changes: 8 additions & 0 deletions test/passing/tests/record.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@ let _ =
()
in
()

let foo
({ foooooooooooooooooooooo
; invalidation_trace
; access_trace
; must_be_valid_reason }
[@warning "+missing-record-field-pattern"] ) =
()
3 changes: 1 addition & 2 deletions test/passing/tests/shortcut_ext_attr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ let () =
match[@foo] () with
| [%foo?
(* Pattern expressions *)
((lazy x)
[@foo] )] ->
((lazy x) [@foo])] ->
()
| [%foo? ((exception x) [@foo])] -> ()]

Expand Down
10 changes: 5 additions & 5 deletions test/passing/tests/source-conventional.ml.err
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Warning: tests/source.ml:926 exceeds the margin
Warning: tests/source.ml:1001 exceeds the margin
Warning: tests/source.ml:6621 exceeds the margin
Warning: tests/source.ml:7079 exceeds the margin
Warning: tests/source.ml:8656 exceeds the margin
Warning: tests/source.ml:925 exceeds the margin
Warning: tests/source.ml:1000 exceeds the margin
Warning: tests/source.ml:6620 exceeds the margin
Warning: tests/source.ml:7078 exceeds the margin
Warning: tests/source.ml:8655 exceeds the margin
3 changes: 1 addition & 2 deletions test/passing/tests/source-conventional.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ let () =
match[@foo] () with
| [%foo?
(* Pattern expressions *)
((lazy x)
[@foo])] ->
((lazy x) [@foo])] ->
()
| [%foo? ((exception x) [@foo])] -> ()]

Expand Down
6 changes: 3 additions & 3 deletions test/passing/tests/source.ml.err
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Warning: tests/source.ml:702 exceeds the margin
Warning: tests/source.ml:2319 exceeds the margin
Warning: tests/source.ml:9158 exceeds the margin
Warning: tests/source.ml:701 exceeds the margin
Warning: tests/source.ml:2318 exceeds the margin
Warning: tests/source.ml:9157 exceeds the margin
3 changes: 1 addition & 2 deletions test/passing/tests/source.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ let () =
match[@foo] () with
| [%foo?
(* Pattern expressions *)
((lazy x)
[@foo] )] ->
((lazy x) [@foo])] ->
()
| [%foo? ((exception x) [@foo])] -> ()]

Expand Down
Loading