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

Keep the location of 'in' keywords in local bindings #2242

Merged
merged 19 commits into from
Feb 16, 2024

Conversation

EmileTrotignon
Copy link
Collaborator

@EmileTrotignon EmileTrotignon commented Jan 24, 2023

Fixes #2096 .
In did this by expanding the let_bindings type to record the loc of the in keyword. Then update_config_maybe_disable uses this loc ('s end) to extract the verbatim code in case of disabling.

@gpetiot gpetiot changed the title add the location of "in" to fix #2096 Keep the location of 'in' keywords in local bindings Jan 30, 2023
@gpetiot gpetiot removed the CLA Signed label Apr 6, 2023
@gpetiot gpetiot force-pushed the disable_local_let branch from a68d651 to e30e233 Compare April 24, 2023 15:12
@gpetiot gpetiot requested a review from Julow April 24, 2023 16:28
Copy link
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice! I just have a comment on the placement of comments.

test/passing/tests/sequence-preserve.ml.ref Outdated Show resolved Hide resolved
CHANGES.md Outdated Show resolved Hide resolved
@hhugo
Copy link
Collaborator

hhugo commented Oct 11, 2023

don't we have the same issue with let module, let exception, let open, .. ?

lib/Fmt_ast.ml Show resolved Hide resolved
lib/Fmt_ast.ml Show resolved Hide resolved
lib/Fmt_ast.ml Show resolved Hide resolved
@EmileTrotignon
Copy link
Collaborator Author

I have rebase and added a fix.

Now the tests are passing, there might be refactoring to do before pushing.

Copy link
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last refactor is nice but I'm not sure I trust the "I checked" comment. How hard would it be to make loc_in not optional ?

lib/Fmt_ast.ml Show resolved Hide resolved
lib/Fmt_ast.ml Outdated
~message:
"Bug in the parser : let bindings with an should always \
have a matching loc_in"
loc_in }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not satisfying as fmt_let is not specific to an ast node and could be reused for other purposes.
Also, I doubt it as pvbs_loc_in is an option.

Copy link
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice improvement to the code and a bug fix. I have a few comments but otherwise it's already ready to merge.

@@ -4393,18 +4393,18 @@ and fmt_let c ~ext ~rec_flag ~bindings ~parens ~fmt_atrs ~fmt_expr ~body_loc
in
let fmt_binding ~first ~last binding =
let ext = if first then ext else None in
let in_ indent = fmt_if_k last (fmt_in indent) in
let in_ =
if last then Some {txt= (fun indent -> fmt_in indent); loc= loc_in}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not everyone has seen a (int -> Fmt.t) loc option in its life.

To be clear, this is fine.

Comment on lines 1831 to 1832
| let_bindings(no_ext) mkrhs(IN) class_expr
{ class_of_let_bindings ~loc:$sloc ~loc_in:$2.loc $1 $3 }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it weird to use mkrhs but then discard the result. Otherwise:

Suggested change
| let_bindings(no_ext) mkrhs(IN) class_expr
{ class_of_let_bindings ~loc:$sloc ~loc_in:$2.loc $1 $3 }
| let_bindings(no_ext) IN class_expr
{ class_of_let_bindings ~loc:$sloc ~loc_in:(make_loc $loc($2)) $1 $3 }

What do you think ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes thats fine

| pbop_op = mkrhs(LETOP) bindings = letop_bindings IN body = seq_expr
| let_bindings(ext) mkrhs(IN) seq_expr
{ expr_of_let_bindings ~loc:$sloc ~loc_in:$2.loc $1 $3 }
| pbop_op = mkrhs(LETOP) bindings = letop_bindings _in_kw=IN body = seq_expr
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it prefixed with _ ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it is unused : we only access the loc, and the way menhir does its cuisine, asking for the loc does make the variable used.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know. Seems like a bug in menhir.

@@ -1113,7 +1116,7 @@ and value_bindings =
{
pvbs_bindings: value_binding list;
pvbs_rec: rec_flag;
pvbs_extension: string loc option
pvbs_extension: string loc option;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary diff. We are careful with diffs in this file as we regularly have to backport changes to it.

@Julow
Copy link
Collaborator

Julow commented Feb 16, 2024

Perfect, let's merge!

@Julow Julow merged commit 137e61c into ocaml-ppx:main Feb 16, 2024
9 of 10 checks passed
Julow added a commit to Julow/opam-repository that referenced this pull request Nov 29, 2024
….27.0)

CHANGES:

### Highlight

- \* Support OCaml 5.2 syntax (ocaml-ppx/ocamlformat#2519, ocaml-ppx/ocamlformat#2544, ocaml-ppx/ocamlformat#2590, ocaml-ppx/ocamlformat#2596, ocaml-ppx/ocamlformat#2621, ocaml-ppx/ocamlformat#2628, @Julow, @EmileTrotignon, @hhugo)
  This includes local open in types, raw identifiers, and the new
  representation for functions.
  This might change the formatting of some functions due to the formatting code
  being completely rewritten.

- Support OCaml 5.3 syntax (ocaml-ppx/ocamlformat#2609, ocaml-ppx/ocamlformat#2610, ocaml-ppx/ocamlformat#2611, ocaml-ppx/ocamlformat#2622, ocaml-ppx/ocamlformat#2623, ocaml-ppx/ocamlformat#2562, ocaml-ppx/ocamlformat#2624, ocaml-ppx/ocamlformat#2625, ocaml-ppx/ocamlformat#2627, @Julow, @Zeta611)
  This adds support for effect patterns, short functor type arguments and utf8
  identifiers.
  To format code using the new `effect` syntax, add this option to your
  `.ocamlformat`:
  ```
  ocaml-version = 5.3
  ```

- Documentation comments are now formatted by default (ocaml-ppx/ocamlformat#2390, @Julow)
  Use the option `parse-docstrings = false` to restore the previous behavior.

- \* Consistent indentation of polymorphic variant arguments (ocaml-ppx/ocamlformat#2427, @Julow)
  Increases the indentation by one to make the formatting consistent with
  normal variants. For example:
  ```
    ...
    (* before *)
      (`Msg
        (foo bar))
    (* after *)
      (`Msg
         (foo bar))
  ```

- Build on OCaml 5.3 (ocaml-ppx/ocamlformat#2603, @adamchol, @Julow)

### Added

- Improve the emacs plugin (ocaml-ppx/ocamlformat#2577, ocaml-ppx/ocamlformat#2600, @gridbugs, @thibautbenjamin)
  Allow a custom command to be used to run ocamlformat and add compatibility
  with emacs ocaml tree-sitter modes.

- Added option `let-binding-deindent-fun` (ocaml-ppx/ocamlformat#2521, @henrytill)
  to control the indentation of the `fun` in:
  ```
  let f =
   fun foo ->
    bar
  ```

- Added back the flag `--disable-outside-detected-project` (ocaml-ppx/ocamlformat#2439, @gpetiot)
  It was removed in version 0.22.

- Support newer Odoc syntax (ocaml-ppx/ocamlformat#2631, ocaml-ppx/ocamlformat#2632, ocaml-ppx/ocamlformat#2633, @Julow)

### Changed

- \* Consistent formatting of comments (ocaml-ppx/ocamlformat#2371, ocaml-ppx/ocamlformat#2550, @Julow)
  This is mostly an internal change but some comments might be formatted differently.

- \* Improve formatting of type constraints with type variables (ocaml-ppx/ocamlformat#2437, @gpetiot)
  For example:
  ```
  let f : type a b c.
      a -> b -> c =
    ...
  ```

- \* Improve formatting of functor arguments (ocaml-ppx/ocamlformat#2505, @Julow)
  This also reduce the indentation of functor arguments with long signatures.

- Improvements to the Janestreet profile (ocaml-ppx/ocamlformat#2445, ocaml-ppx/ocamlformat#2314, ocaml-ppx/ocamlformat#2460, ocaml-ppx/ocamlformat#2593, ocaml-ppx/ocamlformat#2612, @Julow, @tdelvecchio-jsc)

- \* Undo let-bindings and methods normalizations (ocaml-ppx/ocamlformat#2523, ocaml-ppx/ocamlformat#2529, @gpetiot)
  This remove the rewriting of some forms of let-bindings and methods:
  + `let f x = (x : int)` is no longer rewritten into `let f x : int = x`
  + `let f (type a) (type b) ...` is no longer rewritten into `let f (type a b) ...`
  + `let f = fun x -> ...` is no longer rewritten into `let f x = ...`

- \* The `break-colon` option is now taken into account for method type constraints (ocaml-ppx/ocamlformat#2529, @gpetiot)

- \* Force a break around comments following an infix operator (fix non-stabilizing comments) (ocaml-ppx/ocamlformat#2478, @gpetiot)
  This adds a line break:
  ```
    a
    ||
    (* this comment is now on its own line *)
    b
  ```

### Fixed

- Fix placement of comments in some cases (ocaml-ppx/ocamlformat#2471, ocaml-ppx/ocamlformat#2503, ocaml-ppx/ocamlformat#2506, ocaml-ppx/ocamlformat#2540, ocaml-ppx/ocamlformat#2541, ocaml-ppx/ocamlformat#2592, ocaml-ppx/ocamlformat#2617, @gpetiot, @Julow)
  Some comments were being moved or causing OCamlformat to crash.
  OCamlformat refuses to format if a comment would be missing in its output, to avoid loosing code.

- Fix attributes being dropped or moved (ocaml-ppx/ocamlformat#2247, ocaml-ppx/ocamlformat#2459, ocaml-ppx/ocamlformat#2551, ocaml-ppx/ocamlformat#2564, ocaml-ppx/ocamlformat#2602, @EmileTrotignon, @tdelvecchio-jsc, @Julow)
  OCamlformat refuses to format if the formatted code has a different meaning than the original code, for example, if an attribute is removed.
  We also try to avoid moving attributes even if that doesn't change the original code, for example we no longer format `open[@attr] M` as `open M [@@attr]`.

- Remove trailing space inside a wrapping empty signature (ocaml-ppx/ocamlformat#2443, @Julow)
- Fix extension-point spacing in structures (ocaml-ppx/ocamlformat#2450, @Julow)
- \* Consistent break after string constant argument (ocaml-ppx/ocamlformat#2453, @Julow)
- \* Fix cinaps comment formatting to not change multiline string contents (ocaml-ppx/ocamlformat#2463, @tdelvecchio-jsc)
- \* Fix the indentation of tuples in attributes and extensions (ocaml-ppx/ocamlformat#2488, @Julow)
- \* Fix weird indentation and line breaks after comments (ocaml-ppx/ocamlformat#2507, ocaml-ppx/ocamlformat#2589, ocaml-ppx/ocamlformat#2606, @Julow)
- \* Fix unwanted alignment in if-then-else (ocaml-ppx/ocamlformat#2511, @Julow)
- Fix missing parentheses around constraint expressions with attributes (ocaml-ppx/ocamlformat#2513, @alanechang)
- Fix formatting of type vars in GADT constructors (ocaml-ppx/ocamlformat#2518, @Julow)
- Fix `[@ocamlformat "disable"]` in some cases (ocaml-ppx/ocamlformat#2242, ocaml-ppx/ocamlformat#2525, @EmileTrotignon)
  This caused a bug inside `class type` constructs and when attached to a `let ... in`
- Display `a##b` instead of `a ## b` and similarly for operators that start with # (ocaml-ppx/ocamlformat#2580, @v-gb)
- \* Fix arrow type indentation with `break-separators=before` (ocaml-ppx/ocamlformat#2598, @Julow)
- Fix missing parentheses around a let in class expressions (ocaml-ppx/ocamlformat#2599, @Julow)
- Fix formatting of paragraphs in lists in documentation (ocaml-ppx/ocamlformat#2607, @Julow)
- Avoid unwanted space in references and links text in documentation (ocaml-ppx/ocamlformat#2608, @Julow)
- \* Improve the indentation of attributes in patterns (ocaml-ppx/ocamlformat#2613, @Julow)
- \* Avoid large indentation in patterns after `let%ext` (ocaml-ppx/ocamlformat#2615, @Julow)
Julow added a commit to Julow/opam-repository that referenced this pull request Nov 29, 2024
….27.0)

CHANGES:

### Highlight

- \* Support OCaml 5.2 syntax (ocaml-ppx/ocamlformat#2519, ocaml-ppx/ocamlformat#2544, ocaml-ppx/ocamlformat#2590, ocaml-ppx/ocamlformat#2596, ocaml-ppx/ocamlformat#2621, ocaml-ppx/ocamlformat#2628, @Julow, @EmileTrotignon, @hhugo)
  This includes local open in types, raw identifiers, and the new
  representation for functions.
  This might change the formatting of some functions due to the formatting code
  being completely rewritten.

- Support OCaml 5.3 syntax (ocaml-ppx/ocamlformat#2609, ocaml-ppx/ocamlformat#2610, ocaml-ppx/ocamlformat#2611, ocaml-ppx/ocamlformat#2622, ocaml-ppx/ocamlformat#2623, ocaml-ppx/ocamlformat#2562, ocaml-ppx/ocamlformat#2624, ocaml-ppx/ocamlformat#2625, ocaml-ppx/ocamlformat#2627, @Julow, @Zeta611)
  This adds support for effect patterns, short functor type arguments and utf8
  identifiers.
  To format code using the new `effect` syntax, add this option to your
  `.ocamlformat`:
  ```
  ocaml-version = 5.3
  ```

- Documentation comments are now formatted by default (ocaml-ppx/ocamlformat#2390, @Julow)
  Use the option `parse-docstrings = false` to restore the previous behavior.

- \* Consistent indentation of polymorphic variant arguments (ocaml-ppx/ocamlformat#2427, @Julow)
  Increases the indentation by one to make the formatting consistent with
  normal variants. For example:
  ```
    ...
    (* before *)
      (`Msg
        (foo bar))
    (* after *)
      (`Msg
         (foo bar))
  ```

- Build on OCaml 5.3 (ocaml-ppx/ocamlformat#2603, @adamchol, @Julow)

### Added

- Improve the emacs plugin (ocaml-ppx/ocamlformat#2577, ocaml-ppx/ocamlformat#2600, @gridbugs, @thibautbenjamin)
  Allow a custom command to be used to run ocamlformat and add compatibility
  with emacs ocaml tree-sitter modes.

- Added option `let-binding-deindent-fun` (ocaml-ppx/ocamlformat#2521, @henrytill)
  to control the indentation of the `fun` in:
  ```
  let f =
   fun foo ->
    bar
  ```

- Added back the flag `--disable-outside-detected-project` (ocaml-ppx/ocamlformat#2439, @gpetiot)
  It was removed in version 0.22.

- Support newer Odoc syntax (ocaml-ppx/ocamlformat#2631, ocaml-ppx/ocamlformat#2632, ocaml-ppx/ocamlformat#2633, @Julow)

### Changed

- \* Consistent formatting of comments (ocaml-ppx/ocamlformat#2371, ocaml-ppx/ocamlformat#2550, @Julow)
  This is mostly an internal change but some comments might be formatted differently.

- \* Improve formatting of type constraints with type variables (ocaml-ppx/ocamlformat#2437, @gpetiot)
  For example:
  ```
  let f : type a b c.
      a -> b -> c =
    ...
  ```

- \* Improve formatting of functor arguments (ocaml-ppx/ocamlformat#2505, @Julow)
  This also reduce the indentation of functor arguments with long signatures.

- Improvements to the Janestreet profile (ocaml-ppx/ocamlformat#2445, ocaml-ppx/ocamlformat#2314, ocaml-ppx/ocamlformat#2460, ocaml-ppx/ocamlformat#2593, ocaml-ppx/ocamlformat#2612, @Julow, @tdelvecchio-jsc)

- \* Undo let-bindings and methods normalizations (ocaml-ppx/ocamlformat#2523, ocaml-ppx/ocamlformat#2529, @gpetiot)
  This remove the rewriting of some forms of let-bindings and methods:
  + `let f x = (x : int)` is no longer rewritten into `let f x : int = x`
  + `let f (type a) (type b) ...` is no longer rewritten into `let f (type a b) ...`
  + `let f = fun x -> ...` is no longer rewritten into `let f x = ...`

- \* The `break-colon` option is now taken into account for method type constraints (ocaml-ppx/ocamlformat#2529, @gpetiot)

- \* Force a break around comments following an infix operator (fix non-stabilizing comments) (ocaml-ppx/ocamlformat#2478, @gpetiot)
  This adds a line break:
  ```
    a
    ||
    (* this comment is now on its own line *)
    b
  ```

### Fixed

- Fix placement of comments in some cases (ocaml-ppx/ocamlformat#2471, ocaml-ppx/ocamlformat#2503, ocaml-ppx/ocamlformat#2506, ocaml-ppx/ocamlformat#2540, ocaml-ppx/ocamlformat#2541, ocaml-ppx/ocamlformat#2592, ocaml-ppx/ocamlformat#2617, @gpetiot, @Julow)
  Some comments were being moved or causing OCamlformat to crash.
  OCamlformat refuses to format if a comment would be missing in its output, to avoid loosing code.

- Fix attributes being dropped or moved (ocaml-ppx/ocamlformat#2247, ocaml-ppx/ocamlformat#2459, ocaml-ppx/ocamlformat#2551, ocaml-ppx/ocamlformat#2564, ocaml-ppx/ocamlformat#2602, @EmileTrotignon, @tdelvecchio-jsc, @Julow)
  OCamlformat refuses to format if the formatted code has a different meaning than the original code, for example, if an attribute is removed.
  We also try to avoid moving attributes even if that doesn't change the original code, for example we no longer format `open[@attr] M` as `open M [@@attr]`.

- Remove trailing space inside a wrapping empty signature (ocaml-ppx/ocamlformat#2443, @Julow)
- Fix extension-point spacing in structures (ocaml-ppx/ocamlformat#2450, @Julow)
- \* Consistent break after string constant argument (ocaml-ppx/ocamlformat#2453, @Julow)
- \* Fix cinaps comment formatting to not change multiline string contents (ocaml-ppx/ocamlformat#2463, @tdelvecchio-jsc)
- \* Fix the indentation of tuples in attributes and extensions (ocaml-ppx/ocamlformat#2488, @Julow)
- \* Fix weird indentation and line breaks after comments (ocaml-ppx/ocamlformat#2507, ocaml-ppx/ocamlformat#2589, ocaml-ppx/ocamlformat#2606, @Julow)
- \* Fix unwanted alignment in if-then-else (ocaml-ppx/ocamlformat#2511, @Julow)
- Fix missing parentheses around constraint expressions with attributes (ocaml-ppx/ocamlformat#2513, @alanechang)
- Fix formatting of type vars in GADT constructors (ocaml-ppx/ocamlformat#2518, @Julow)
- Fix `[@ocamlformat "disable"]` in some cases (ocaml-ppx/ocamlformat#2242, ocaml-ppx/ocamlformat#2525, @EmileTrotignon)
  This caused a bug inside `class type` constructs and when attached to a `let ... in`
- Display `a##b` instead of `a ## b` and similarly for operators that start with # (ocaml-ppx/ocamlformat#2580, @v-gb)
- \* Fix arrow type indentation with `break-separators=before` (ocaml-ppx/ocamlformat#2598, @Julow)
- Fix missing parentheses around a let in class expressions (ocaml-ppx/ocamlformat#2599, @Julow)
- Fix formatting of paragraphs in lists in documentation (ocaml-ppx/ocamlformat#2607, @Julow)
- Avoid unwanted space in references and links text in documentation (ocaml-ppx/ocamlformat#2608, @Julow)
- \* Improve the indentation of attributes in patterns (ocaml-ppx/ocamlformat#2613, @Julow)
- \* Avoid large indentation in patterns after `let%ext` (ocaml-ppx/ocamlformat#2615, @Julow)
Julow added a commit to Julow/opam-repository that referenced this pull request Dec 2, 2024
….27.0)

CHANGES:

### Highlight

- \* Support OCaml 5.2 syntax (ocaml-ppx/ocamlformat#2519, ocaml-ppx/ocamlformat#2544, ocaml-ppx/ocamlformat#2590, ocaml-ppx/ocamlformat#2596, ocaml-ppx/ocamlformat#2621, ocaml-ppx/ocamlformat#2628, @Julow, @EmileTrotignon, @hhugo)
  This includes local open in types, raw identifiers, and the new
  representation for functions.
  This might change the formatting of some functions due to the formatting code
  being completely rewritten.

- Support OCaml 5.3 syntax (ocaml-ppx/ocamlformat#2609, ocaml-ppx/ocamlformat#2610, ocaml-ppx/ocamlformat#2611, ocaml-ppx/ocamlformat#2622, ocaml-ppx/ocamlformat#2623, ocaml-ppx/ocamlformat#2562, ocaml-ppx/ocamlformat#2624, ocaml-ppx/ocamlformat#2625, ocaml-ppx/ocamlformat#2627, @Julow, @Zeta611)
  This adds support for effect patterns, short functor type arguments and utf8
  identifiers.
  To format code using the new `effect` syntax, add this option to your
  `.ocamlformat`:
  ```
  ocaml-version = 5.3
  ```

- Documentation comments are now formatted by default (ocaml-ppx/ocamlformat#2390, @Julow)
  Use the option `parse-docstrings = false` to restore the previous behavior.

- \* Consistent indentation of polymorphic variant arguments (ocaml-ppx/ocamlformat#2427, @Julow)
  Increases the indentation by one to make the formatting consistent with
  normal variants. For example:
  ```
    ...
    (* before *)
      (`Msg
        (foo bar))
    (* after *)
      (`Msg
         (foo bar))
  ```

- Build on OCaml 5.3 (ocaml-ppx/ocamlformat#2603, @adamchol, @Julow)

### Added

- Improve the emacs plugin (ocaml-ppx/ocamlformat#2577, ocaml-ppx/ocamlformat#2600, @gridbugs, @thibautbenjamin)
  Allow a custom command to be used to run ocamlformat and add compatibility
  with emacs ocaml tree-sitter modes.

- Added option `let-binding-deindent-fun` (ocaml-ppx/ocamlformat#2521, @henrytill)
  to control the indentation of the `fun` in:
  ```
  let f =
   fun foo ->
    bar
  ```

- Added back the flag `--disable-outside-detected-project` (ocaml-ppx/ocamlformat#2439, @gpetiot)
  It was removed in version 0.22.

- Support newer Odoc syntax (ocaml-ppx/ocamlformat#2631, ocaml-ppx/ocamlformat#2632, ocaml-ppx/ocamlformat#2633, @Julow)

### Changed

- \* Consistent formatting of comments (ocaml-ppx/ocamlformat#2371, ocaml-ppx/ocamlformat#2550, @Julow)
  This is mostly an internal change but some comments might be formatted differently.

- \* Improve formatting of type constraints with type variables (ocaml-ppx/ocamlformat#2437, @gpetiot)
  For example:
  ```
  let f : type a b c.
      a -> b -> c =
    ...
  ```

- \* Improve formatting of functor arguments (ocaml-ppx/ocamlformat#2505, @Julow)
  This also reduce the indentation of functor arguments with long signatures.

- Improvements to the Janestreet profile (ocaml-ppx/ocamlformat#2445, ocaml-ppx/ocamlformat#2314, ocaml-ppx/ocamlformat#2460, ocaml-ppx/ocamlformat#2593, ocaml-ppx/ocamlformat#2612, @Julow, @tdelvecchio-jsc)

- \* Undo let-bindings and methods normalizations (ocaml-ppx/ocamlformat#2523, ocaml-ppx/ocamlformat#2529, @gpetiot)
  This remove the rewriting of some forms of let-bindings and methods:
  + `let f x = (x : int)` is no longer rewritten into `let f x : int = x`
  + `let f (type a) (type b) ...` is no longer rewritten into `let f (type a b) ...`
  + `let f = fun x -> ...` is no longer rewritten into `let f x = ...`

- \* The `break-colon` option is now taken into account for method type constraints (ocaml-ppx/ocamlformat#2529, @gpetiot)

- \* Force a break around comments following an infix operator (fix non-stabilizing comments) (ocaml-ppx/ocamlformat#2478, @gpetiot)
  This adds a line break:
  ```
    a
    ||
    (* this comment is now on its own line *)
    b
  ```

### Fixed

- Fix placement of comments in some cases (ocaml-ppx/ocamlformat#2471, ocaml-ppx/ocamlformat#2503, ocaml-ppx/ocamlformat#2506, ocaml-ppx/ocamlformat#2540, ocaml-ppx/ocamlformat#2541, ocaml-ppx/ocamlformat#2592, ocaml-ppx/ocamlformat#2617, @gpetiot, @Julow)
  Some comments were being moved or causing OCamlformat to crash.
  OCamlformat refuses to format if a comment would be missing in its output, to avoid loosing code.

- Fix attributes being dropped or moved (ocaml-ppx/ocamlformat#2247, ocaml-ppx/ocamlformat#2459, ocaml-ppx/ocamlformat#2551, ocaml-ppx/ocamlformat#2564, ocaml-ppx/ocamlformat#2602, @EmileTrotignon, @tdelvecchio-jsc, @Julow)
  OCamlformat refuses to format if the formatted code has a different meaning than the original code, for example, if an attribute is removed.
  We also try to avoid moving attributes even if that doesn't change the original code, for example we no longer format `open[@attr] M` as `open M [@@attr]`.

- Remove trailing space inside a wrapping empty signature (ocaml-ppx/ocamlformat#2443, @Julow)
- Fix extension-point spacing in structures (ocaml-ppx/ocamlformat#2450, @Julow)
- \* Consistent break after string constant argument (ocaml-ppx/ocamlformat#2453, @Julow)
- \* Fix cinaps comment formatting to not change multiline string contents (ocaml-ppx/ocamlformat#2463, @tdelvecchio-jsc)
- \* Fix the indentation of tuples in attributes and extensions (ocaml-ppx/ocamlformat#2488, @Julow)
- \* Fix weird indentation and line breaks after comments (ocaml-ppx/ocamlformat#2507, ocaml-ppx/ocamlformat#2589, ocaml-ppx/ocamlformat#2606, @Julow)
- \* Fix unwanted alignment in if-then-else (ocaml-ppx/ocamlformat#2511, @Julow)
- Fix missing parentheses around constraint expressions with attributes (ocaml-ppx/ocamlformat#2513, @alanechang)
- Fix formatting of type vars in GADT constructors (ocaml-ppx/ocamlformat#2518, @Julow)
- Fix `[@ocamlformat "disable"]` in some cases (ocaml-ppx/ocamlformat#2242, ocaml-ppx/ocamlformat#2525, @EmileTrotignon)
  This caused a bug inside `class type` constructs and when attached to a `let ... in`
- Display `a##b` instead of `a ## b` and similarly for operators that start with # (ocaml-ppx/ocamlformat#2580, @v-gb)
- \* Fix arrow type indentation with `break-separators=before` (ocaml-ppx/ocamlformat#2598, @Julow)
- Fix missing parentheses around a let in class expressions (ocaml-ppx/ocamlformat#2599, @Julow)
- Fix formatting of paragraphs in lists in documentation (ocaml-ppx/ocamlformat#2607, @Julow)
- Avoid unwanted space in references and links text in documentation (ocaml-ppx/ocamlformat#2608, @Julow)
- \* Improve the indentation of attributes in patterns (ocaml-ppx/ocamlformat#2613, @Julow)
- \* Avoid large indentation in patterns after `let%ext` (ocaml-ppx/ocamlformat#2615, @Julow)
Julow added a commit to Julow/opam-repository that referenced this pull request Dec 2, 2024
….27.0)

CHANGES:

### Highlight

- \* Support OCaml 5.2 syntax (ocaml-ppx/ocamlformat#2519, ocaml-ppx/ocamlformat#2544, ocaml-ppx/ocamlformat#2590, ocaml-ppx/ocamlformat#2596, ocaml-ppx/ocamlformat#2621, ocaml-ppx/ocamlformat#2628, @Julow, @EmileTrotignon, @hhugo)
  This includes local open in types, raw identifiers, and the new
  representation for functions.
  This might change the formatting of some functions due to the formatting code
  being completely rewritten.

- Support OCaml 5.3 syntax (ocaml-ppx/ocamlformat#2609, ocaml-ppx/ocamlformat#2610, ocaml-ppx/ocamlformat#2611, ocaml-ppx/ocamlformat#2622, ocaml-ppx/ocamlformat#2623, ocaml-ppx/ocamlformat#2562, ocaml-ppx/ocamlformat#2624, ocaml-ppx/ocamlformat#2625, ocaml-ppx/ocamlformat#2627, @Julow, @Zeta611)
  This adds support for effect patterns, short functor type arguments and utf8
  identifiers.
  To format code using the new `effect` syntax, add this option to your
  `.ocamlformat`:
  ```
  ocaml-version = 5.3
  ```

- Documentation comments are now formatted by default (ocaml-ppx/ocamlformat#2390, @Julow)
  Use the option `parse-docstrings = false` to restore the previous behavior.

- \* Consistent indentation of polymorphic variant arguments (ocaml-ppx/ocamlformat#2427, @Julow)
  Increases the indentation by one to make the formatting consistent with
  normal variants. For example:
  ```
    ...
    (* before *)
      (`Msg
        (foo bar))
    (* after *)
      (`Msg
         (foo bar))
  ```

- Build on OCaml 5.3 (ocaml-ppx/ocamlformat#2603, @adamchol, @Julow)

### Added

- Improve the emacs plugin (ocaml-ppx/ocamlformat#2577, ocaml-ppx/ocamlformat#2600, @gridbugs, @thibautbenjamin)
  Allow a custom command to be used to run ocamlformat and add compatibility
  with emacs ocaml tree-sitter modes.

- Added option `let-binding-deindent-fun` (ocaml-ppx/ocamlformat#2521, @henrytill)
  to control the indentation of the `fun` in:
  ```
  let f =
   fun foo ->
    bar
  ```

- Added back the flag `--disable-outside-detected-project` (ocaml-ppx/ocamlformat#2439, @gpetiot)
  It was removed in version 0.22.

- Support newer Odoc syntax (ocaml-ppx/ocamlformat#2631, ocaml-ppx/ocamlformat#2632, ocaml-ppx/ocamlformat#2633, @Julow)

### Changed

- \* Consistent formatting of comments (ocaml-ppx/ocamlformat#2371, ocaml-ppx/ocamlformat#2550, @Julow)
  This is mostly an internal change but some comments might be formatted differently.

- \* Improve formatting of type constraints with type variables (ocaml-ppx/ocamlformat#2437, @gpetiot)
  For example:
  ```
  let f : type a b c.
      a -> b -> c =
    ...
  ```

- \* Improve formatting of functor arguments (ocaml-ppx/ocamlformat#2505, @Julow)
  This also reduce the indentation of functor arguments with long signatures.

- Improvements to the Janestreet profile (ocaml-ppx/ocamlformat#2445, ocaml-ppx/ocamlformat#2314, ocaml-ppx/ocamlformat#2460, ocaml-ppx/ocamlformat#2593, ocaml-ppx/ocamlformat#2612, @Julow, @tdelvecchio-jsc)

- \* Undo let-bindings and methods normalizations (ocaml-ppx/ocamlformat#2523, ocaml-ppx/ocamlformat#2529, @gpetiot)
  This remove the rewriting of some forms of let-bindings and methods:
  + `let f x = (x : int)` is no longer rewritten into `let f x : int = x`
  + `let f (type a) (type b) ...` is no longer rewritten into `let f (type a b) ...`
  + `let f = fun x -> ...` is no longer rewritten into `let f x = ...`

- \* The `break-colon` option is now taken into account for method type constraints (ocaml-ppx/ocamlformat#2529, @gpetiot)

- \* Force a break around comments following an infix operator (fix non-stabilizing comments) (ocaml-ppx/ocamlformat#2478, @gpetiot)
  This adds a line break:
  ```
    a
    ||
    (* this comment is now on its own line *)
    b
  ```

### Fixed

- Fix placement of comments in some cases (ocaml-ppx/ocamlformat#2471, ocaml-ppx/ocamlformat#2503, ocaml-ppx/ocamlformat#2506, ocaml-ppx/ocamlformat#2540, ocaml-ppx/ocamlformat#2541, ocaml-ppx/ocamlformat#2592, ocaml-ppx/ocamlformat#2617, @gpetiot, @Julow)
  Some comments were being moved or causing OCamlformat to crash.
  OCamlformat refuses to format if a comment would be missing in its output, to avoid loosing code.

- Fix attributes being dropped or moved (ocaml-ppx/ocamlformat#2247, ocaml-ppx/ocamlformat#2459, ocaml-ppx/ocamlformat#2551, ocaml-ppx/ocamlformat#2564, ocaml-ppx/ocamlformat#2602, @EmileTrotignon, @tdelvecchio-jsc, @Julow)
  OCamlformat refuses to format if the formatted code has a different meaning than the original code, for example, if an attribute is removed.
  We also try to avoid moving attributes even if that doesn't change the original code, for example we no longer format `open[@attr] M` as `open M [@@attr]`.

- Remove trailing space inside a wrapping empty signature (ocaml-ppx/ocamlformat#2443, @Julow)
- Fix extension-point spacing in structures (ocaml-ppx/ocamlformat#2450, @Julow)
- \* Consistent break after string constant argument (ocaml-ppx/ocamlformat#2453, @Julow)
- \* Fix cinaps comment formatting to not change multiline string contents (ocaml-ppx/ocamlformat#2463, @tdelvecchio-jsc)
- \* Fix the indentation of tuples in attributes and extensions (ocaml-ppx/ocamlformat#2488, @Julow)
- \* Fix weird indentation and line breaks after comments (ocaml-ppx/ocamlformat#2507, ocaml-ppx/ocamlformat#2589, ocaml-ppx/ocamlformat#2606, @Julow)
- \* Fix unwanted alignment in if-then-else (ocaml-ppx/ocamlformat#2511, @Julow)
- Fix missing parentheses around constraint expressions with attributes (ocaml-ppx/ocamlformat#2513, @alanechang)
- Fix formatting of type vars in GADT constructors (ocaml-ppx/ocamlformat#2518, @Julow)
- Fix `[@ocamlformat "disable"]` in some cases (ocaml-ppx/ocamlformat#2242, ocaml-ppx/ocamlformat#2525, @EmileTrotignon)
  This caused a bug inside `class type` constructs and when attached to a `let ... in`
- Display `a##b` instead of `a ## b` and similarly for operators that start with # (ocaml-ppx/ocamlformat#2580, @v-gb)
- \* Fix arrow type indentation with `break-separators=before` (ocaml-ppx/ocamlformat#2598, @Julow)
- Fix missing parentheses around a let in class expressions (ocaml-ppx/ocamlformat#2599, @Julow)
- Fix formatting of paragraphs in lists in documentation (ocaml-ppx/ocamlformat#2607, @Julow)
- Avoid unwanted space in references and links text in documentation (ocaml-ppx/ocamlformat#2608, @Julow)
- \* Improve the indentation of attributes in patterns (ocaml-ppx/ocamlformat#2613, @Julow)
- \* Avoid large indentation in patterns after `let%ext` (ocaml-ppx/ocamlformat#2615, @Julow)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Crash on [@ocamlformat disabled] on local function
5 participants