Skip to content

Format compiler sources with ocamlformat #6901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 10, 2024

Conversation

aspeddro
Copy link
Contributor

@aspeddro aspeddro commented Jul 22, 2024

This PR is a proposal to add ocamlformat on test group with-test and ocaml-lsp-server to the with-dev-setup group. A feature introduced in opam v2.2.0

Currently ocamlformat is a standard dependency and there are several .ocamlformat with disable which disables formatting. I actually don't know why.

One problem is synchronizing ocamlformat and ocaml-lsp-server since ocamlformat is a dependency on ocaml-lsp-server see rescript-lang/rescript-vscode#832. This generates some conflicts because in CONTRIBUTING.md it is instructed to install ocaml-lsp-server separately.

By marking ocamlformat(with-test) and ocaml-lsp-server with with-dev-setup we can synchronize boths.

Other changes

  • I deleted all .ocamlformat with disable
  • Added some files in .ocamlformat-ignore. This files has top level directive #if
  • Formated files
  • Added format check on CI

Now we can format on save.

@aspeddro aspeddro marked this pull request as ready for review July 22, 2024 00:46
@aspeddro
Copy link
Contributor Author

js_parser should be ignored, right?

@cknitt
Copy link
Member

cknitt commented Jul 22, 2024

Thanks a lot, @aspeddro!

Some remarks:

@cristianoc
Copy link
Collaborator

Thanks a lot, @aspeddro!

Some remarks:

Reformatting ml is good. It was postponed because some cppo preprocessing was not compatible.
The only thing is, this should be merged when there are hardly any outstanding PRs, or one will get horrible conflicts.

@aspeddro aspeddro force-pushed the opam-2.0-dev-setup branch from d827c56 to 1d123e0 Compare July 22, 2024 13:50
@cknitt
Copy link
Member

cknitt commented Jul 22, 2024

Reformatting ml is good. It was postponed because some cppo preprocessing was not compatible.
The only thing is, this should be merged when there are hardly any outstanding PRs, or one will get horrible conflicts.

I would then suggest that we wait until 12.0-alpha.1 is out (including @cristianoc's latest uncurried cleanup work) and I have done the backports to the v11 branch. Then would be a good time to do the reformatting before starting the work on alpha 2.

Another thing: After this PR, ocaml-lsp-server will be installed in CI (unnecessarily). Not sure if that's much an issue though now that @cometkim has improved opam caching.

@aspeddro
Copy link
Contributor Author

Ok, added jscom/js_parser/** in .ocamlformat-ignore and removed .{ml,mli} changes (easier to sync with master)

@aspeddro
Copy link
Contributor Author

Another thing: After this PR, ocaml-lsp-server will be installed in CI (unnecessarily)

I think it might be useful in the process of updating ocamlformat and ocaml-lsp-server. To ensure that there is no conflict between the two.

@cometkim
Copy link
Member

cometkim commented Jul 22, 2024

After this PR, ocaml-lsp-server will be installed in CI (unnecessarily).

A common strategy is to separate the dev-only and build-only workflows and run them simultaneously. As I mentioned in here

But it will duplicates cache, I think intalling deps including dev-setup is good enough for now

@cknitt
Copy link
Member

cknitt commented Oct 9, 2024

  • I deleted all .ocamlformat with disable

I don't see that in the current changes.

@aspeddro aspeddro force-pushed the opam-2.0-dev-setup branch from 9903d90 to ff1b756 Compare October 9, 2024 18:23
@aspeddro
Copy link
Contributor Author

aspeddro commented Oct 9, 2024

After this PR, ocaml-lsp-server will be installed in CI (unnecessarily)

I added ocamlformat to the test group (with-test). ocaml-lsp-server is no longer installed no CI

@aspeddro
Copy link
Contributor Author

aspeddro commented Oct 9, 2024

I don't see that in the current changes.

Updated

@aspeddro
Copy link
Contributor Author

aspeddro commented Oct 9, 2024

@cknitt, If everything is ok I can format the files to pass the test.

Copy link
Member

@cknitt cknitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot! Looks good to me.

@cknitt
Copy link
Member

cknitt commented Oct 9, 2024

@cristianoc @zth Fine with you, too?

Copy link
Member

@tsnobip tsnobip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR! I can't count how many times I had to struggle to sync ocaml lsp and ocamlformat when working on the compiler.

@cknitt cknitt changed the title opam 2.2.0: add with-dev-setup group Format compiler sources with ocamlformat Oct 10, 2024
@cknitt cknitt merged commit 44e9786 into rescript-lang:master Oct 10, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants