Closed joprice closed 4 years ago
@joprice see comment about cppo:
Ah, so Parses without any preprocessing
means I shouldn't expect this to be supported unless ocamlformat decided to support bucklescript explicitly? If that's the case, I assume it would lead people not to use conditional compilation at all when already using ocamlformat, or reduce use of conditional compilation to files with very little source that don't benefit from automated formatting in the first place.
Perhaps there could be an alternate syntax for conditional compilation that is defined within comments?
That is already true. And cppo is the standard for conditional compilation. Same applies to the reason formatter at the moment. This for example does not format: https://github.com/cristianoc/reanalyze/blob/master/src/Compat.re
And I get annoying errors in the editor.
reduce use of conditional compilation to files with very little source that don't benefit from automated formatting in the first place.
This is the suggested practice.
Perhaps there could be an alternate syntax for conditional compilation that is defined within comments?
This is an interesting idea that's worth exploring. But not all formatters will preserve comments faithfully, so it is quite fragile.
There's no actionable items we can do here, so I am going to close it
Maybe you could reuse the syntax from ppx_optcomp
[%%if ocaml_version < (4, 02, 0)]
let x = 1
[%%else]
let y = 2
[%%endif]
@hhugo does that work with ocamlformat?
Yes. It's standard ocaml syntax (extension points and attributes)
Looks a little strange in .re
but it reformats:
%if
ocaml_version < (4, 02, 0);
let x = 1;
[%%else];
let y = 2;
[%%endif];
I'll give ppx_optcomp a try.
Mmm looks like esy complains about some dependencies. OK never mind then, not going to debug that.
ocamlformat preserves short/long syntax for extension point. refmt should probably do the same.
With a file with the following source:
running ocamlformat results in this error:
As a workaround, I can add the file to
.ocamlformat-ignore
so that my formatting script in ci doesn't fail and not format the rest of the process.I recognize that this might be less supported since bsrefmt might be more frequently used for bucklescript projects, but there is at least no mention in the preprocessor docs of this incompatibility https://bucklescript.github.io/docs/en/conditional-compilation#docsNav and actually mentions that it is expected to work with exiting tooling:
It’s purely functional and type-safe, and cooperates with editor tooling like Merlin
. Is this a known issue?Env: