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

Fix multilines for OCaml block in .mli file #395

Merged
merged 5 commits into from
Aug 31, 2022

Conversation

panglesd
Copy link
Collaborator

@panglesd panglesd commented Aug 30, 2022

This small PR fixes the fact that, in OCaml blocks, in .mli files, the indentation was erased to a "only 2 space relative to the opening bracket" indentation.

For instance,

(**
{[
  match None with
  | None -> ()
  | Some a -> match a with
    | None -> ()
    | Some _ -> ()
]}
*)

was turned into

(**
{[
  match None with
  | None -> ()
  | Some a -> match a with
  | None -> ()
  | Some _ -> ()
]}
*)

which is not ideal.

The first commit adds a test, showing the wrong behaviour,. The second commit is the patch and updates the test.
The new behaviour is the first line is indented two spaces after the opening bracket, and for other lines the indentation relative to the first one is kept, as long as they are at least as indented as the first one. In the previous example, the exact indententation would be kept.

In the test, I also added that multilines in .mli files for toplevel block does not work!

Signed-off-by: Paul-Elliot <peada@free.fr>
@panglesd panglesd changed the title Fix multilines ocaml Fix multilines for OCaml block in .mli file Aug 30, 2022
Signed-off-by: Paul-Elliot <peada@free.fr>
Copy link
Collaborator

@Leonidas-from-XIV Leonidas-from-XIV left a comment

Choose a reason for hiding this comment

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

Thanks @panglesd for your contribution! It looks nice and we should be able to merge it soon, there's just some small things that would be nice to improve beforehand.

test/bin/mdx-test/expect/multilines-mli/test-case.mli Outdated Show resolved Hide resolved
lib/block.ml Outdated Show resolved Hide resolved
@Leonidas-from-XIV
Copy link
Collaborator

Oh, as I am seeing the CI runs, can you add a changelog entry?

`Int.min` was introduced in OCaml 4.13

Signed-off-by: Paul-Elliot <peada@free.fr>
Signed-off-by: Paul-Elliot <peada@free.fr>
Signed-off-by: Paul-Elliot <peada@free.fr>
@Leonidas-from-XIV Leonidas-from-XIV merged commit d7fb2b7 into realworldocaml:main Aug 31, 2022
@Leonidas-from-XIV
Copy link
Collaborator

Thanks @panglesd for your help, I'll try to bundle a few of these fixes that have PRs and make a release soon.

@realworldocaml realworldocaml deleted a comment Oct 24, 2022
Leonidas-from-XIV added a commit to Leonidas-from-XIV/opam-repository that referenced this pull request Jan 6, 2023
CHANGES:

#### Added

- Report all parsing errors in Markdown files (realworldocaml/mdx#389, @NathanReb)

#### Changed

- Preserve indentation in multiline OCaml blocks in .mli files (realworldocaml/mdx#395, @panglesd)

#### Fixed

- Fixed compatibility with Cmdliner 1.1.0 (realworldocaml/mdx#371, @Leonidas-from-XIV)
- Report errors and exit codes of toplevel directives (realworldocaml/mdx#382, @talex5,
  @Leonidas-from-XIV)
- Fix block locations in error reporting (realworldocaml/mdx#389, @NathanReb)
- Include the content of the line that features the `part-end` MDX directive in
  the output, before that line would've been dropped (realworldocaml/mdx#374, realworldocaml/mdx#387,
  @Leonidas-from-XIV)
- Handle EINTR signal on waitpid call by restarting the syscall. (realworldocaml/mdx#409, @tmcgilchrist)
- Fix parsing of multiline toplevel phrases in .mli files (realworldocaml/mdx#394, realworldocaml/mdx#397,
  @Leonidas-from-XIV)

#### Removed

- Removed warning about missing semicolons added in MDX 1.11.0 and the
  automatic insertion of semicolons in the corrected files introduced in MDX
  2.0.0. (realworldocaml/mdx#398, @Leonidas-from-XIV)
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.

2 participants