dune
dune copied to clipboard
Support formatting mld files
Ocamlformat 0.25.0 added support for .mld files (https://github.com/ocaml-ppx/ocamlformat/pull/2008).
Currently, dune fmt won't run ocamlformat on .mld files. If the user is using a version of ocamlformat that supports it (> 0.25.0), it'd be great if Dune ran ocamlformat on .mld files.
If the user is using a version of ocamlformat that supports it (> 0.25.0)
We don't have access to that information from Dune unfortunately.
We could add support for that in an opt-in way in the meantime but there's some work involved (I don't think that the set of things we can enable formatting for supports :standard at the moment).
I don't see any reason why we couldn't know the ocamlformat version. We do similar version queries for ocaml and Coq.
Indeed, that's not a hard limitation.
@rgrinberg did you intend to set the label and milestone for this issue? I'm asking because this isn't about mdx (and I don't think that it needs to be done for 3.8)
Enabling mdx stanza 0.4 could trigger passing mld files to ocamlformat by default, but it could also be part of later mdx stanzas.
Actually rather than asking ocamlformat, shouldn't we be getting the ocamlformat version from the .ocamlformat file?
Actually rather than asking ocamlformat, shouldn't we be getting the ocamlformat version from the .ocamlformat file?
If it's present, yes, but the version field isn't required so dune would still need to get the version somewhere if it can't find it in the configuration.
I am not sure it is a good idea to enable it depending on the version of ocamlformat that is installed without declaring it in any configuration file (.ocamlformat or dune-project), because that means that different people could end up with different formatting results.
I think that the .ocamlformat file should be the main source of truth and the version reported by ocamlformat should be a fallback when it is not available. Ocamlformat already errors if both versions are incompatible. If both versions are unavailable, then we should avoid any version specific code anyway.