Skip to content

Feature request: interpret normal comments like doc comments (as ocp-indent does) #1165

@ceastlund

Description

@ceastlund

Is your feature request related to a problem? Please describe.
There is currently a round-trip problem when running code through ocamlformat and then ocp-indent. Consider code like this:

type t =
  { field : ty
  (* Here is some verbatim formatted text:
     {v
       starting at column 7
     v}*)
  }

If I run it through ocamlformat as of a906b5d, I get the following:

type t =
  { field : ty
        (* Here is some verbatim formatted text:
           {v
             starting at column 7
           v}*)
  }

The whole comment has been indented uniformly, as ocamlformat puts comments on fields farther to the right than that.
Now if I run that result through ocp-indent, I get this:

type t =
  { field : ty
  (* Here is some verbatim formatted text:
     {v
             starting at column 7
           v}*)
  }

Now ocp-indent has moved the comment back to the left. However, because it treates {v ... v} as a verbatim block, it left it indented further to the right.
If I then save this code, and run it through ocamlformat and ocp-indent again, that comment will move several spaces further to the right, and on and on. The process does not have a fixed point.

For our current workflow at Jane Street of using ocamlformat with ocp-indent, I think we need one of (a) consistent comment handling between ocp-indent and ocamlformat, (b) ocamlformat not to move any whitespace within comments, or (c) ocamlformat to offer editor integration so we can drop ocp-indent. Pretty clearly (a) is preferable to (b), and I expect (c) is a much bigger lift, but any of the above will alleviate the immediate problem for us.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions