dune icon indicating copy to clipboard operation
dune copied to clipboard

Support formatting mld files

Open tmattio opened this issue 2 years ago • 9 comments

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.

tmattio avatar Apr 13 '23 16:04 tmattio

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).

emillon avatar Apr 20 '23 09:04 emillon

I don't see any reason why we couldn't know the ocamlformat version. We do similar version queries for ocaml and Coq.

Alizter avatar Apr 20 '23 12:04 Alizter

Indeed, that's not a hard limitation.

emillon avatar Apr 20 '23 12:04 emillon

@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)

emillon avatar Apr 21 '23 09:04 emillon

Enabling mdx stanza 0.4 could trigger passing mld files to ocamlformat by default, but it could also be part of later mdx stanzas.

Leonidas-from-XIV avatar Apr 21 '23 13:04 Leonidas-from-XIV

Actually rather than asking ocamlformat, shouldn't we be getting the ocamlformat version from the .ocamlformat file?

Alizter avatar Apr 21 '23 23:04 Alizter

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.

tmattio avatar Apr 22 '23 13:04 tmattio

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.

Leonidas-from-XIV avatar Apr 24 '23 09:04 Leonidas-from-XIV

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.

Alizter avatar Apr 24 '23 12:04 Alizter