Skip to content
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

Provide ocamlformat-rpc through the ocamlformat package #2035

Merged
merged 7 commits into from
Mar 10, 2022

Conversation

gpetiot
Copy link
Collaborator

@gpetiot gpetiot commented Mar 3, 2022

Reverts some bits of #2022

cc @rgrinberg
cc @tmattio since you opened #2022

@gpetiot gpetiot added the no changelog set this to bypass the CI check for changelog entries label Mar 3, 2022
@gpetiot gpetiot requested a review from Julow March 3, 2022 17:29
"alcotest" {with-test}
"ocamlformat" {= version}
Copy link
Contributor

Choose a reason for hiding this comment

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

The dune file still lists ocamlformat as a library dependency. Where would that dependency come from if this package is removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's because #2022 renamed ocamlformat_lib to ocamlformat, but this dependency was always here.

Copy link
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

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

I think this was necessary. Both the library and the binary are part of the ocamlformat package, Dune won't build if it isn't installed first:

$ dune build -p ocamlformat-rpc-lib,ocamlformat-rpc
File "lib-rpc-server/dune", line 4, characters 12-23:
4 |  (libraries ocamlformat ocamlformat-rpc-lib))
                ^^^^^^^^^^^
Error: Library "ocamlformat" not found.

For this to work, the library should be moved to its own package.
What about building the RPC server as part of the main package ? This way people can forget about whether they want the RPC or the binary and just have both.

@tmattio
Copy link
Contributor

tmattio commented Mar 4, 2022

What about building the RPC server as part of the main package ? This way people can forget about whether they want the RPC or the binary and just have both.

This would also improve the UX with ocaml-lsp. The fact that you need to install both ocamlformat and ocamlformat-rpc as a dependency is a little awkward.

@gpetiot
Copy link
Collaborator Author

gpetiot commented Mar 4, 2022

Is this what you had in mind? I'm just worried about the .mld file I had to rename to avoid having 2 index.mld in a single package, I hope it will properly show up in the v3 online documentation.

@Julow
Copy link
Collaborator

Julow commented Mar 4, 2022

It doesn't build because now the ocamlformat packages requires ocamlformat-rpc-lib:

$ dune build -p ocamlformat
File "lib-rpc-server/dune", line 4, characters 24-43:
4 |  (libraries ocamlformat ocamlformat-rpc-lib))
                            ^^^^^^^^^^^^^^^^^^^
Error: Library "ocamlformat-rpc-lib" not found.

This dependency was useful to be sure the encoder/decoder functions are in sync but is not fundamentally required and brings a lot of dangerous code into the server impl. It should be possible to copy the few needed functions into the server instead.

The documentation doesn't work because there's no link to it from the index.mld. You could move all the doc into a single place to make things easier.

@gpetiot
Copy link
Collaborator Author

gpetiot commented Mar 4, 2022

Would it be such a bad thing to add a dependency to ocamlformat-rpc-lib in ocamlformat instead of duplicating code?

@Julow
Copy link
Collaborator

Julow commented Mar 7, 2022

Would it be such a bad thing to add a dependency to ocamlformat-rpc-lib in ocamlformat instead of duplicating code?

I think it's not that much duplication, given that this dependency doesn't make much sense in the first place. The rpc-lib API doesn't make sense for a server and is here just to share a few decode functions (that don't need to be shared anyway).

@gpetiot
Copy link
Collaborator Author

gpetiot commented Mar 7, 2022

The rpc-lib API doesn't make sense for a server and is here just to share a few decode functions (that don't need to be shared anyway).

I think if makes sense to avoid duplicating the whole ocamlformat_rpc_lib file, since the whole is functorized over the IO module now we can't just the the bits we need. Or maybe we need to redesign the whole thing again.

@Julow
Copy link
Collaborator

Julow commented Mar 7, 2022

Here's a way to remove the dependency but still share the serialization/deserialization code: gpetiot#12
This approach requires changing the API of lib-rpc but has the advantage of not linking unrelated code into the server. The new API should be slightly cleaner and still allow users to implement a server or a client.

@gpetiot gpetiot changed the title ocamlformat-rpc: Remove dependency on ocamlformat Provide ocamlformat-rpc as part of ocamlformat Mar 8, 2022
@gpetiot gpetiot changed the title Provide ocamlformat-rpc as part of ocamlformat Provide ocamlformat-rpc through the ocamlformat package Mar 8, 2022
gpetiot and others added 7 commits March 8, 2022 14:38
* lib-rpc: Split "protocol" and "client"

The Protocol module defines the serializing and deserializing code for
commands. The main Make functor now only defines the client API.

Command types are no longer exposed, the Client API is more focused.

* Remove dependency between main package and lib-rpc

Define a library from copied modules from the lib-rpc library. These two
modules are present in both library.

* Remove unecessary template file

* rpc: Fix the doc

Link to the new page and move it to the doc directory.
@gpetiot
Copy link
Collaborator Author

gpetiot commented Mar 8, 2022

@Julow thanks, I agree with your changes!

@rgrinberg @ulugbekna @tmattio @panglesd let us know if everything is alright for you then we can merge.

@gpetiot gpetiot requested a review from Julow March 8, 2022 14:42
@panglesd
Copy link
Contributor

panglesd commented Mar 9, 2022

Looks good to me!

@rgrinberg
Copy link
Contributor

I won't be able to review, sorry. But from my perspective, if it's possible to use the rpc lib without depending on anything else, it's enough.

Copy link
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

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

If the API changes to lib-rpc are not an issue, this can be merged.

@gpetiot gpetiot merged commit 1f59ddf into ocaml-ppx:main Mar 10, 2022
@gpetiot gpetiot deleted the fix-deps branch March 10, 2022 10:50
mseri pushed a commit to ocaml/opam-repository that referenced this pull request May 26, 2022
CHANGES:

### Removed

- Profiles `compact` and `sparse` are now removed (ocaml-ppx/ocamlformat#2075, @gpetiot)
- Options `align-cases`, `align-constructors-decl` and `align-variants-decl` are now removed (ocaml-ppx/ocamlformat#2076, @gpetiot)
- Option `disable-outside-detected-project` is now removed (ocaml-ppx/ocamlformat#2077, @gpetiot)

### Deprecated

- Cancel the deprecations of options that are not set by the preset profiles (ocaml-ppx/ocamlformat#2074, @gpetiot)

### Bug fixes

- emacs: Remove temp files in the event of an error (ocaml-ppx/ocamlformat#2003, @gpetiot)
- Fix unstable comment formatting around prefix op (ocaml-ppx/ocamlformat#2046, @gpetiot)

### Changes

- Qtest comments are not re-formatted (ocaml-ppx/ocamlformat#2034, @gpetiot)
- ocamlformat-rpc is now distributed through the ocamlformat package (ocaml-ppx/ocamlformat#2035, @Julow)
- Doc-comments code blocks with a language other than 'ocaml' (set in metadata) are not parsed as OCaml (ocaml-ppx/ocamlformat#2037, @gpetiot)
- More comprehensible error message in case of version mismatch (ocaml-ppx/ocamlformat#2042, @gpetiot)
- The global configuration file (`$XDG_CONFIG_HOME` or `$HOME/.config`) is only applied when no project is detected, `--enable-outside-detected-project` is set, and no applicable `.ocamlformat` file has been found. Global and local configurations are no longer used at the same time. (ocaml-ppx/ocamlformat#2039, @gpetiot)
- Set `ocaml-version` to a fixed version (4.04.0) by default to avoid reproducibility issues and surprising behaviours (ocaml-ppx/ocamlformat#2064, @kit-ty-kate)
- Split option `--numeric=X-Y` into `--range=X-Y` and `--numeric` (flag). For now `--range` can only be used with `--numeric`. (ocaml-ppx/ocamlformat#2073, ocaml-ppx/ocamlformat#2082, @gpetiot)

### New features

- New syntax `(*= ... *)` for verbatim comments (ocaml-ppx/ocamlformat#2028, @gpetiot)
- Preserve the begin-end construction in the AST (ocaml-ppx/ocamlformat#1785, @hhugo, @gpetiot)
- Preserve position of comments located after the semi-colon of the last element of lists/arrays/records (ocaml-ppx/ocamlformat#2032, @gpetiot)
- Option `--print-config` displays a warning when an .ocamlformat file defines redundant options (already defined by a profile) (ocaml-ppx/ocamlformat#2084, @gpetiot)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changelog set this to bypass the CI check for changelog entries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants