ocamlformat icon indicating copy to clipboard operation
ocamlformat copied to clipboard

Alignment of multiline doc comments

Open Julow opened this issue 6 years ago • 4 comments

With --profile=conventional:

  (** fooo fooo
    fooo *)
  let fooo = 1

The item got moved inside a module (it was previously at toplevel). Second line of the docstring did not get indented. This is fixed by --parse-docstrings but it's not in the conventional profile.

Julow avatar Oct 02 '19 16:10 Julow

Yes it is due to the wrap-comments=false of this profile that keep the comments unchanged (you may not want the second line indented for whatever reason), if you indent it by hand, you get the expected result.

gpetiot avatar Oct 03 '19 07:10 gpetiot

In that case, the global indentation changed. The second line was correctly aligned, by hand. Should we adjust the indentation in that case ?

Julow avatar Oct 03 '19 09:10 Julow

What I mean is that, as seen below, the comments are not modified in both cases, but if you indent it manually before formatting like in the second case, the output is what is expected:

module M = struct      
  (** fooo fooo
    fooo *)
  let fooo = 1

  (** fooo fooo
      fooo *)
  let fooo = 1
end

I don't think ocamlformat does anything wrong here.

gpetiot avatar Oct 03 '19 09:10 gpetiot

I mean, if you wrap everything in a module (so you need to add a level of indentation) and use ocamlformat to do that for you, the doc comments will not be indented correctly.

(** fooo fooo
    fooo *)
let fooo = 1

then

module M = struct
(** fooo fooo
    fooo *)
let fooo = 1
end

gives

module M = struct      
  (** fooo fooo
    fooo *)
  let fooo = 1
end

Julow avatar Oct 03 '19 09:10 Julow