odoc icon indicating copy to clipboard operation
odoc copied to clipboard

Incorrect rejection of `{[ ]}` docstring

Open jberdine opened this issue 3 years ago • 8 comments

Code such as:

type sp =
  | Blank  (** {[ ]} *)

leads to a warning such as

Warning: Invalid documentation comment:
File "lib/Fmt.mli", line 23, characters 15-20:
'{[...]}' (code block) should not be empty.

There isn't any indication in the spec that the "preformatted source code style" should not be a single space. And for the warning in particular, being preformatted, a single space is not empty.

jberdine avatar Jul 21 '21 12:07 jberdine

If you need a solution now you can likely use a non-breaking space (U+00A0) to work around (didn't try, but that usually works most of the time when you hit silly things like that).

dbuenzli avatar Jul 21 '21 14:07 dbuenzli

Odoc's spec is not exactly ocamldoc's one and there's no written spec currently. The warning is from Odoc's parser, which strip the spaces. It is possible to fix this in Odoc by moving this check further in the pipeline (there's already a place for these checks) or removing it completely.

Julow avatar Jul 21 '21 14:07 Julow

you can likely use a non-breaking space (U+00A0) to work around

Thanks @dbuenzli, that is helpful.

jberdine avatar Jul 21 '21 16:07 jberdine

Odoc's spec is not exactly ocamldoc's one and there's no written spec currently.

The situation where odoc consciously disagrees with the OCaml manual, and doesn't have a spec itself, is a continuing issue. Are there any plans in this ?

jberdine avatar Jul 21 '21 16:07 jberdine

It is possible to fix this in Odoc by moving this check further in the pipeline (there's already a place for these checks) or removing it completely.

Wait, you closed this a a bit quickly. This issue has a point: I don't really see the purpose of this check and it probably shouldn't be there.

Drup avatar Jul 21 '21 16:07 Drup

Wait, you closed this a a bit quickly

Indeed ! Sorry about that. I thought I was reading an issue on OCamlformat's repository.

Julow avatar Jul 21 '21 17:07 Julow

is there a usecase for a codeblock containing a single space, given that it's indistinguishable from a blank line? ([ ] would be distinguishable from [] though) maybe jberdine wants an inline preformatted code span rather than a code block, which i don't believe exists currently?

asavahista avatar Sep 24 '21 03:09 asavahista

There is a need for both "preformatted" elements, {[...]} in ocamldoc, and (not preformatted) "code" elements, [...] in ocamldoc. It seems that odoc makes a distinction between "inline" and non-inline (is this the same as the "span" vs "block" distinction), and interprets ocamldoc's "preformatted" as "non-inline", and "non-preformatted" as "inline".

My understanding is that the tension is conflating preformatted vs not with non-inline vs not, and that at least preformatted and non-preformatted possibly inline elements are needed. In the context of ocamlformat we should leave preformatted elements as they are, but format the non-preformatted ones. Whether they are inline or not is not as important in this context, as the non-preformatted ones will be broken across lines if they are long. But the formatting shouldn't break/change the odoc parsed form, which highlights the tension.

I wonder if it would be feasible to extend odoc's parse tree to be able to express both preformatted vs not and inline vs not, and to use {[...]} for preformatted and [...] for non-preformatted, and to identify non-inline elements as those without newlines after [ and before ], probably modulo whitespace.

jberdine avatar Oct 01 '21 12:10 jberdine