ocamlformat icon indicating copy to clipboard operation
ocamlformat copied to clipboard

Bug: Spaces added to preformatted code style docstring elements

Open jberdine opened this issue 4 years ago • 4 comments

Describe the bug Formatting code such as:

type sp =
  | Cut  (** {[@,]} *)

adds spaces within the preformatted code element, producing

type sp =
  | Cut  (** {[ @, ]} *)

How to Reproduce Change the Cut docstring in Fmt.mli as above and make test.

jberdine avatar Jul 21 '21 12:07 jberdine

That's the formatting we expect, to separate the heavier syntax {[ from the bigger piece of code. Perhaps the source can be changed to use [ ... ] instead, which is expected to contain a small bit of code and isn't formatted by ocamlformat.

Note that this code block will appear heavy in Odoc's output.

Julow avatar Jul 21 '21 14:07 Julow

I don't know what would look better in odoc's output, I'm neutral regarding using wrap "[@;<1 2>" "@ ]" or wrap "[@;<0 2>" "@,]", but I admit having spaces added can be surprising

gpetiot avatar Jul 21 '21 15:07 gpetiot

Maybe it is just me, but my interpretation of "preformatted" in the spec makes me think that adding spaces is quite surprising.

jberdine avatar Jul 21 '21 16:07 jberdine

Odoc doesn't follow ocamldoc in a lot of cases. Odoc is not sensitive to whitespaces around {[ and ]} and to the indentation of the whole block. It's reasonable to add spaces and newlines here and to indent the whole block. (we do all this)

Julow avatar Jul 21 '21 17:07 Julow