Js#11
Open
J494-bit wants to merge 680 commits into
Open
Conversation
Author
|
Go |
ghost
approved these changes
Jan 5, 2023
Speedytats
approved these changes
Mar 8, 2023
Speedytats
approved these changes
Mar 8, 2023
harshsingh32
approved these changes
Apr 18, 2023
cesarapascual
approved these changes
Apr 19, 2023
* De-indent the `object` keyword in class types The previous indentation of the keyword was ambiguous as it was aligned with the previous and next lines. This is similar to the formatting of module `struct`. * Ensure comments, doc, attrs and parens are formatted for class types
A comment just before a constructor in a type declaration was causing the argument of the constructor to be formatted in vertical style. The constructor is now formatted the same as if there were no comment.
* test_branch: Print tested versions When looking at the diffs on Github, it can be reassuring to see that the versions being tested are right. * Don't checkout the merge commit
Improve ocp-indent-compat for many nodes: * `fun` and `function` expressions * Doc in record and variant declarations * Pexp_constraint * Module expr constraint * Pmty_with * Indent wrapping type constrs * Assignment operators * Annotation of module unpack * Fun arguments (The box structure needs to be tweaked) Added the `Params.Indent` module for keeping these functions together.
* Make sure not to break out-of-margin emtpy-sig
* preview_new_release: Remove alcotest and tezos * preview_new_release: Option to apply a previous version first An executable can be passed to the new `-b` option, it will be applied in a first pass and the result will be commited. This ensures that the preview commit shows only the diff caused by the new version.
These files slow down backporting upstream changes as well as making further changes to the extended parser.
Structure items with an extension were formatted in a compact way when `module-item-spacing=compact` even though the similar items without an extension would not. This is a problem in future work where the `Pstr_extension` node is no longer used.
Co-authored-by: Jules Aguillon <jules@j3s.fr>
A break is added after wrapping string constants in argument lists. This break was missing for string constants containing explicit line breaks or format hints.
This argument doesn't work similarly to the `~epi` argument of other functions. It meant different things depending on the expression: - `Pexp_match` and `Pexp_apply`: it was similar to `~pro`. - `Pexp_constant`: like the usual `~epi` but was passed a break. - all other cases: it was not used. These rules are now handled in `fmt_args_grouped`, the only place where they made sense. The `~epi` argument is removed. In the first case, the `~pro` argument is used instead. This requires refactoring `fmt_expression` to make sure that every cases use `~pro` exactly once.
This fixes a regression introduced in #1672 making --no-comment-check less useful.
* Fix redundancy in letop-punning tests * Notes on adding a test in CONTRIBUTING * CHANGES entry * Edits per @EmileTrotignon * Typo repair * Edits per @Julow
* letop-punning for extension nodes * Update CHANGES.md Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Fix comments getting dropped by letop-punning=always --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Currently, Cmdliner is given a formatter that drops any text, but Cmdliner can (and does) print whitespace via the non-overridden out_spaces, out_indent and out_newlines.
These locations, which are new in 5.4, are sometimes traversed (e.g. Pexp_setfield) and
sometimes not (e.g. Pexp_field). So clearly a bug.
The fix is concretely:
- change map_loc to map over both fields `{ loc; txt }` of `Location.loc`
- propagate the change, ie change `map_loc` to `map_string_loc`,
`map_string_opt_loc` or `map_loc_lid` depending on the type. All occurrences
of the latter are bug fixes.
* Support the new functor type syntax `MT -> MT`
Support the unnamed functor parameters in module types:
module type F = ARG -> S
The extended parser is changed to preserve the concrete syntax of
functor arguments in module types. Notably, these three lines are no
longer equivalent and the first two are no longer turned into the third:
module M : (_ : S) -> (_ : S) -> S = N
module M : S -> S -> S = N
module M : (_ : S) (_ : S) -> S = N
Update to the new Odoc features: - @toc_status and @order_category - Structured code block tags syntax - Indentation of code and verbatim blocks Also backported formatting changes and code changes. * odoc-parser: Code block and verbatim blocks indentation change Odoc now strips the indentation from code and verbatim blocks. It doesn't use the indentation of the least indented line, like OCamlformat, but instead use the indentation of the block opening. * odoc: Normalize `\\n` into newline In code blocks, newlines can be turned into `\\n` (or the opposite) when formatting string literals that need to break. Update the normalization function to avoid crashing when that happens. * odoc: Remove extra indentation in code blocks The updated Odoc parser considers that code blocks horizontally start at the opening bracket. It no longer uses the indentation of the least indented line for that. As a result, OCamlformat cannot indent code blocks without changing their content. The indentation is also removed in code blocks that are formatted, to avoid adding visible indentation in rendered documentation. * odoc: Don't fail for removed whitespaces in code blocks During normalisation, allow whitespaces to disappear from code blocks. This happens when code if formatted.
* Missing parens in module type `(M with type ..) -> N` Fix the parenthesing rules for `with type` inside functors and functors inside `with type`. * Fix short-syntax functor formatting
* use special case beginend syntax in match cases when possible * also allow `if then begin match` * changelog * changelog * fmt
Co-authored-by: Jules Aguillon <jules@j3s.fr>
* parser-std: Backport polymorphic paramters From ocaml/ocaml#13806 * parser-ext: Backport polymorphic parameters * Fix Ast rules for Ptyp_poly It is treated with the same precedence as Ptyp_arrow.
* parser-std: Backport Ppat_unpack
Also backport the `map_loc` change in `Ast_mapper`.
* parser-ext: Backport Ppat_unpack
We already did a similar change in the past, the parsetree doesn't
change.
* parser-ext: Backport Ast_mapper map_loc changes
* Disable rewriting rule for Ppat_unpack
It is no longer valid to rewrite:
((module M) : (module S))
into:
(module M : S)
The original string syntax (eg. `{del| .. |del}`) is not respected
because this is probably unecessary.
An minimal unsafe version of Domain.DLS is used to implement Format_. This shim module just needs to be removed if OCamlformat ever use parallelism. * Disable scan_push bug fix This bug fix breaks OCamlformat and will be fixed in a separate PR.
Improve the formatting of:
module type of M
with module A = A (*test*)
`Pexp_struct_item` replaces `Pexp_letexception`, `Pexp_letmodule` and `Pexp_letopen`. The code for the old constructs is removed and replaced by a call to `fmt_structure_item`. The code for formatting structure items is changed to propagate the `~pro` and `~epi` arguments. * Extend the context for embedded struct items The `Str_exp` context is needed to apply the `let_module` option. The `Mb` context constructor is extended to carry the parent context, which would otherwise be erased before `fmt_module` gets called.
Backport modular explicits syntax. The test code is taken from the compiler's testsuite. * Factorize the formatting of package types This removes code with seamingly no regressions.
Backport refactors and other changes made upstream that do not change the language syntax. The goal is to reduce the diff with upstream to make future updates easier. * Reduce diff in arg_label The location is different but no comment moved in the tests.
* Add more tests for let-struct-items Taken from the compiler's testsuite.
This reduce the indentation of the `begin` keyword in this case:
let () =
if true then (* a *)
begin
()
end
else ()
and fixes an instability issue when the comment was big enough.
The special handling of empty files by the (diff) rule is removed in Dune 3.22: ocaml/dune#13696 Promote the empty error files to avoid build errors.
This was caught by opam-repository CI and caused by the vendored modules from the compiler's source.
…it-or-vertical` (#2797) * Fix instability with if-then-else=fit-or-vertical and comments after then When using if-then-else=fit-or-vertical, a comment placed between the `then` keyword and the branch expression caused an infinite oscillation between two formats: then (* comment *) <--> then expr (* comment *) expr The root cause is that the hovbox's soft break (break 1 2) in branch_pro allows the comment to fit on the same line as `then` when the hovbox doesn't break. On re-parsing, the comment is then classified as 'after the then keyword' instead of 'before the expression', producing a different layout that breaks back to the other form. Fix: in the Fit_or_vertical case, when the expression is multi-line and there is no begin..end or keyword comment, use cmts_before_opt to check for and consume comments before the branch body directly in branch_pro, placing them with a forced line break so the comment stays on its own indented line. The single-line check ensures short expressions that fit on one line are unaffected.
…vertical (#2798) When a `match expr with` appeared as a branch of `if-then-else` with `if-then-else=fit-or-vertical`, the match keyword, scrutinee, and `with` were broken onto separate lines even when they easily fit on one line: if true then match expr with | true -> () | false -> () The regression was introduced by 8056fa5 ("Overhaul begin match formatting"), which changed `fmt_match` to wrap `pro` inside a nested `hvbox 0 (pro_inner $ keyword)`. When the match is inside an if-then-else branch, the `pro` carries a `break_unless_newline 1000 2` (from the Fit_or_vertical branch_pro). This inflates the inner hvbox's size to 1000+, causing the Format engine to classify the parent hovbox as non-fitting, which forces all breaks in the `match .. expr .. with` box to break. Fix: in `match_inner_pro`, return `false` for `Pexp_ifthenelse` context (same as already done for `Pexp_infix`), so that `pro` is placed outside the match's inner hvbox as `pro_outer`, where it does not interfere with the match keyword/expr/with fitting on one line.
* Fix formatting oscillation in if-then-else branches When a comment sits between a keyword (then/else) and certain branch expressions (begin...end wrapping match/try/function/ifthenelse, or bare match/try/function/ifthenelse), the comment would alternate between "after keyword" and "before expression" placements across formatting iterations. This caused branch_pro to compute different indentation each time, producing "formatting did not stabilize after 10 iterations". The fix detects these oscillation-prone patterns and ensures stable formatting regardless of the initial comment placement: - In Fmt_ast, when a branch matches `needs_raw_cmts_after_kw`, extract "after keyword" comments without breaks and override branch_pro using `Params.raw_cmts_branch_pro` (which computes mode-appropriate break+indent+comment output). - In Params, `branch_pro_with_cmts` detects comments "before expression" (the alternate placement) and forces a break, producing the same layout as the "after keyword" path. - For begin...end branches, `branch_pro` checks for comments before the inner expression (not just the begin...end node) to handle the case where the comment migrates inside the begin...end scope. Affected modes: Fit_or_vertical, Compact (profile=conventional). Assisted-by: GitHub Copilot:claude-opus-4-20250514
The root cause was that the ocamlformat executable's internal module
name was main, so dune built `main.exe`. The program derives its
self-name (used in error messages) from `argv.(0)` at
`lib/Translation_unit.ml:37`. Under dune package management:
(setup-dune@v2), `%{bin:ocamlformat}` resolves to the raw `main.exe`
instead of the install-layout `ocamlformat` path, making the
program call itself `main` instead of `ocamlformat`.
Now `argv.(0)` ends in `ocamlformat.exe` in every build mode, so
`exe = "ocamlformat"` consistently. `dune build @test/failing/runtest`
passes locally, and the change is independent of how dune resolves the
binary, so it'll be stable on CI too.
The separate `bin/ocamlformat-rpc/` executable (also internally named
`main`) is untouched.
handle_last_newline scans backward and matches '\n' immediately, leaving
the preceding '\r' (if any) on the stripped string. Because deindent then
splits on '\n' and rejoins with '\n', every '\r' on an intermediate line
ends up followed by a '\n' — but the '\r' on the last line is bare,
since String.concat puts no separator after the final element.
The OCaml lexer's newline regex is '\r*\n', so a bare trailing '\r'
falls through to the Illegal_character rule. This caused the Windows CI
to fail on any {@ocaml[...]} block in a CRLF-checked-out file.
Mirror handle_first_newline (which already eats a leading '\r' before
matching '\n'): when handle_last_newline finds '\n', also drop a
preceding '\r' so the full CRLF is consumed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Me gustaría probar