odoc icon indicating copy to clipboard operation
odoc copied to clipboard

Doc comments on function parameters

Open lukemaurer opened this issue 2 years ago • 3 comments

It would be nice to attach an odoc comment to a function parameter rather than having to mention each parameter in the comment for the whole function. Something like:

(** Do the special thing. *)
val do_it :
  (** What does the thing *)
  t ->
  (** What the thing is done to *)
  target:t ->
  (** The special sauce to use *)
  sauce:Sauce.t ->
  unit

(There's already a wrinkle in that putting the arrows at the starts of lines would would probably cause the comments to attach to different parameters.)

lukemaurer avatar Feb 10 '23 13:02 lukemaurer

I had thought that the compiler already collected these, but looking at the parser it seems not. I think that the attachment rules consistent with the existing ones would have it as:

(** Do the special thing. *)
val do_it :
  t -> (** What does the thing *)
  target:t ->  (** What the thing is done to *)
  sauce:Sauce.t -> (** The special sauce to use *)
  unit

and also including support for:

(** Do the special thing. *)
val do_it :
  t (** What does the thing *)
  -> target:t  (** What the thing is done to *)
  -> sauce:Sauce.t (** The special sauce to use *)
  -> unit

similar to how it's done for ; in records and object types.

lpw25 avatar Feb 10 '23 15:02 lpw25

Makes sense. Certainly, consistency with record syntax is ideal.

lukemaurer avatar Feb 10 '23 18:02 lukemaurer

The attachment rules are indeed "incomplete": they are only there for labelled/optional parameters. But for those they are already there, and it would be nice if odoc propagated them already.

trefis avatar Aug 23 '23 12:08 trefis