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

Allow monadic IO in dot protocol #1581

Merged
merged 4 commits into from
Apr 5, 2023

Conversation

3Rafal
Copy link
Collaborator

@3Rafal 3Rafal commented Mar 17, 2023

As discussed in: ocaml/ocaml-lsp#1052

@3Rafal 3Rafal changed the title refactor: allow monadic IO in dot protocol Allow monadic IO in dot protocol Mar 17, 2023
@voodoos
Copy link
Collaborator

voodoos commented Mar 21, 2023

I think we should use the new interface in Merlin itself and remove the old io functions.
We should also add comments explaining how to use the new interface and maybe point to ocaml-lsp's usage.

@3Rafal 3Rafal force-pushed the monadic-io-in-dot-protocol branch 2 times, most recently from e993323 to a329786 Compare March 24, 2023 12:57
src/dot-protocol/merlin_dot_protocol.mli Outdated Show resolved Hide resolved
src/dot-protocol/merlin_dot_protocol.mli Outdated Show resolved Hide resolved
@3Rafal 3Rafal requested a review from voodoos March 28, 2023 08:41
Copy link
Collaborator

@voodoos voodoos left a comment

Choose a reason for hiding this comment

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

Mostly cosmetic changes...

src/dot-protocol/merlin_dot_protocol.ml Outdated Show resolved Hide resolved
src/dot-protocol/merlin_dot_protocol.ml Outdated Show resolved Hide resolved
src/dot-protocol/merlin_dot_protocol.ml Outdated Show resolved Hide resolved
src/dot-protocol/merlin_dot_protocol.ml Outdated Show resolved Hide resolved
src/dot-protocol/merlin_dot_protocol.mli Outdated Show resolved Hide resolved
src/dot-protocol/merlin_dot_protocol.mli Outdated Show resolved Hide resolved
src/kernel/mconfig_dot.ml Outdated Show resolved Hide resolved
@voodoos voodoos added this to the Next release milestone Mar 28, 2023
@voodoos
Copy link
Collaborator

voodoos commented Mar 28, 2023

Also we will need a changelog entry :-)

3Rafal added a commit to 3Rafal/merlin that referenced this pull request Mar 29, 2023
@3Rafal 3Rafal force-pushed the monadic-io-in-dot-protocol branch from 47b51bd to 84972fc Compare March 29, 2023 09:58
CHANGES.md Outdated Show resolved Hide resolved
@voodoos
Copy link
Collaborator

voodoos commented Mar 29, 2023

Ok, let's stop worrying about the indentation and make this PR the first one to be ocamlformatted.

Can you rebase and clean the history ? Then I will take care of the formatting.

Edit: and factor the functor/module sig

@3Rafal 3Rafal force-pushed the monadic-io-in-dot-protocol branch from 84972fc to 76ed590 Compare March 29, 2023 16:35
@voodoos
Copy link
Collaborator

voodoos commented Mar 29, 2023

Thanks for the changes @3Rafal !

@rgrinberg , do you confirm that the final interface suits your needs ?

@voodoos voodoos merged commit 9fc6355 into ocaml:master Apr 5, 2023

val read : in_chan -> (Csexp.t, string) result IO.t

val write : out_chan -> Csexp.t -> unit IO.t
Copy link
Member

Choose a reason for hiding this comment

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

In the ocamllsp fork, this is a list of csexps, why was this changed to a single csexp?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure. I think the fork uses a single csexp as well.

val write : t -> Csexp.t -> unit IO.t

Copy link
Member

Choose a reason for hiding this comment

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

@ddickstein you might be using an old version somewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you might be misreading. The functor takes a module whose write is implemented in terms of a single csexp. The module that is provided, Lev_fiber_csexp.Session, implements write in terms of a list, so there's a redefinition of write that implements it for the functor by packaging the csexp into a singleton list and calling Lev_fiber_csexp.Session.write. The incompatibility I was pointing out as an issue was on the read side, where the latest version of Merlin now expects the implementation that returns a result, but Lev_fiber_csexp.Session.read returns an option, and there's no re-implementation to satisfy the functor because ocaml-lsp hasn't yet updated to the latest version of Merlin. But I am now on latest Merlin and on latest ocaml-lsp, so I'm seeing an incompatibility.

Copy link
Collaborator

@voodoos voodoos Apr 21, 2023

Choose a reason for hiding this comment

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

Yes, not sure why the result turned into an option, we can easily change that.

However even with that change it is important to note that the current Merlin master should not be expected to be compatible with ocaml-lsp. We still have an upstreaming PR to merge (#1585) and then we will have to make changes to ocaml-lsp to actually use the new api. At that point both projects will we be compatible for the first time.

Copy link
Collaborator Author

@3Rafal 3Rafal Apr 21, 2023

Choose a reason for hiding this comment

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

Implementation used internally by merlin ("Blocking"), uses Csexp library. read is implemented as:

let read = Csexp.input

which has type of

val input : in_channel -> (Sexp.t, string) result

I decided to use result, and then adjust implementation in ocaml-lsp

Copy link
Member

Choose a reason for hiding this comment

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

Whoops, sorry for not reading this closer.

I decided to use result, and then adjust implementation in ocaml-lsp

What would be the purpose of the string in Error case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Currently, the Error string is not used. I reused the old implementation, which worked that way. Do you think it would be a better idea to change the interface to use option?

Copy link
Member

Choose a reason for hiding this comment

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

Nah, the result type is fine. I'm just curious what you plan to use it for. If it's an error message, It's not really possible to display it in a friendly way to an lsp user through the merlin API.

voodoos added a commit to voodoos/merlin that referenced this pull request Apr 28, 2023
from 3Rafal/monadic-io-in-dot-protocol
voodoos added a commit to voodoos/opam-repository that referenced this pull request May 26, 2023
CHANGES:

Fri May 26 15:23:42 CEST 2023

  + merlin binary
    - Allow monadic IO in dot protocol (ocaml/merlin#1581)
    - Add a `scope` option to the `occurrences` command in preparation for
      the upcoming `project-wide-occurrences` feature (ocaml/merlin#1596)
    - Construct bool-typed holes as `false` instead of `true` in the
      `construct` command, for consistency (ocaml/merlin#1599).
    - Add a hook to configure system command for spawning ppxes when Merlin is
      used as a library. (ocaml/merlin#1585)
    - Implement an all-or-nothing cache for the PPX phase (ocaml/merlin#1584)
    - Cleanup functors caches when backtracking, to avoid memory leaks
      (ocaml/merlin#1609, fixes ocaml/merlin#1529 and ocaml-lsp#1032)
    - Fix `construct` results ordering for sum types sand poly variants (ocaml/merlin#1603)
    - Fix object method completion not working (ocaml/merlin#1606, fixes ocaml/merlin#1575)
    - Improve context detection for package types (ocaml/merlin#1608, fixes ocaml/merlin#1607)
    - Fix incorrect locations for string literals (ocaml/merlin#1574)
    - Fixed an issue that caused `errors` to erroneously alert about missing
      `cmi` files (ocaml/merlin#1577)
    - Prevent destruct from crashing on closed variant types (ocaml/merlin#1602,
      fixes ocaml/merlin#1601)
    - Improve longident parsing (ocaml/merlin#1612, fixes ocaml/merlin#945)
  + editor modes
    - emacs: call the user's configured completion UI in
      `merlin-construct` (ocaml/merlin#1598)
  + test suite
    - Add missing dependency to a test using ppxlib (ocaml/merlin#1583)
    - Add tests for the new PPX phase cache (ocaml/merlin#1584)
    - Add and update tests for `construct` ordering (ocaml/merlin#1603)
voodoos added a commit to voodoos/opam-repository that referenced this pull request May 26, 2023
CHANGES:

Fri May 26 15:23:42 CEST 2023

  + merlin binary
    - Allow monadic IO in dot protocol (ocaml/merlin#1581)
    - Add a `scope` option to the `occurrences` command in preparation for
      the upcoming `project-wide-occurrences` feature (ocaml/merlin#1596)
    - Construct bool-typed holes as `false` instead of `true` in the
      `construct` command, for consistency (ocaml/merlin#1599).
    - Add a hook to configure system command for spawning ppxes when Merlin is
      used as a library. (ocaml/merlin#1585)
    - Implement an all-or-nothing cache for the PPX phase (ocaml/merlin#1584)
    - Cleanup functors caches when backtracking, to avoid memory leaks
      (ocaml/merlin#1609, fixes ocaml/merlin#1529 and ocaml-lsp#1032)
    - Fix `construct` results ordering for sum types sand poly variants (ocaml/merlin#1603)
    - Fix object method completion not working (ocaml/merlin#1606, fixes ocaml/merlin#1575)
    - Improve context detection for package types (ocaml/merlin#1608, fixes ocaml/merlin#1607)
    - Fix incorrect locations for string literals (ocaml/merlin#1574)
    - Fixed an issue that caused `errors` to erroneously alert about missing
      `cmi` files (ocaml/merlin#1577)
    - Prevent destruct from crashing on closed variant types (ocaml/merlin#1602,
      fixes ocaml/merlin#1601)
    - Improve longident parsing (ocaml/merlin#1612, fixes ocaml/merlin#945)
  + editor modes
    - emacs: call the user's configured completion UI in
      `merlin-construct` (ocaml/merlin#1598)
  + test suite
    - Add missing dependency to a test using ppxlib (ocaml/merlin#1583)
    - Add tests for the new PPX phase cache (ocaml/merlin#1584)
    - Add and update tests for `construct` ordering (ocaml/merlin#1603)
voodoos added a commit to voodoos/opam-repository that referenced this pull request May 26, 2023
CHANGES:

Fri May 26 15:23:42 CEST 2023

  + merlin binary
    - Allow monadic IO in dot protocol (ocaml/merlin#1581)
    - Add a `scope` option to the `occurrences` command in preparation for
      the upcoming `project-wide-occurrences` feature (ocaml/merlin#1596)
    - Construct bool-typed holes as `false` instead of `true` in the
      `construct` command, for consistency (ocaml/merlin#1599).
    - Add a hook to configure system command for spawning ppxes when Merlin is
      used as a library. (ocaml/merlin#1585)
    - Implement an all-or-nothing cache for the PPX phase (ocaml/merlin#1584)
    - Cleanup functors caches when backtracking, to avoid memory leaks
      (ocaml/merlin#1609, fixes ocaml/merlin#1529 and ocaml-lsp#1032)
    - Fix `construct` results ordering for sum types sand poly variants (ocaml/merlin#1603)
    - Fix object method completion not working (ocaml/merlin#1606, fixes ocaml/merlin#1575)
    - Improve context detection for package types (ocaml/merlin#1608, fixes ocaml/merlin#1607)
    - Fix incorrect locations for string literals (ocaml/merlin#1574)
    - Fixed an issue that caused `errors` to erroneously alert about missing
      `cmi` files (ocaml/merlin#1577)
    - Prevent destruct from crashing on closed variant types (ocaml/merlin#1602,
      fixes ocaml/merlin#1601)
    - Improve longident parsing (ocaml/merlin#1612, fixes ocaml/merlin#945)
  + editor modes
    - emacs: call the user's configured completion UI in
      `merlin-construct` (ocaml/merlin#1598)
  + test suite
    - Add missing dependency to a test using ppxlib (ocaml/merlin#1583)
    - Add tests for the new PPX phase cache (ocaml/merlin#1584)
    - Add and update tests for `construct` ordering (ocaml/merlin#1603)

[new release] merlin, merlin-lib and dot-merlin-reader (4.9-414)

CHANGES:

Fri May 26 15:23:42 CEST 2023

  + merlin binary
    - Allow monadic IO in dot protocol (ocaml/merlin#1581)
    - Add a `scope` option to the `occurrences` command in preparation for
      the upcoming `project-wide-occurrences` feature (ocaml/merlin#1596)
    - Construct bool-typed holes as `false` instead of `true` in the
      `construct` command, for consistency (ocaml/merlin#1599).
    - Add a hook to configure system command for spawning ppxes when Merlin is
      used as a library. (ocaml/merlin#1585)
    - Implement an all-or-nothing cache for the PPX phase (ocaml/merlin#1584)
    - Cleanup functors caches when backtracking, to avoid memory leaks
      (ocaml/merlin#1609, fixes ocaml/merlin#1529 and ocaml-lsp#1032)
    - Fix `construct` results ordering for sum types sand poly variants (ocaml/merlin#1603)
    - Fix object method completion not working (ocaml/merlin#1606, fixes ocaml/merlin#1575)
    - Improve context detection for package types (ocaml/merlin#1608, fixes ocaml/merlin#1607)
    - Fix incorrect locations for string literals (ocaml/merlin#1574)
    - Fixed an issue that caused `errors` to erroneously alert about missing
      `cmi` files (ocaml/merlin#1577)
    - Prevent destruct from crashing on closed variant types (ocaml/merlin#1602,
      fixes ocaml/merlin#1601)
    - Improve longident parsing (ocaml/merlin#1612, fixes ocaml/merlin#945)
  + editor modes
    - emacs: call the user's configured completion UI in
      `merlin-construct` (ocaml/merlin#1598)
  + test suite
    - Add missing dependency to a test using ppxlib (ocaml/merlin#1583)
    - Add tests for the new PPX phase cache (ocaml/merlin#1584)
    - Add and update tests for `construct` ordering (ocaml/merlin#1603)
voodoos added a commit to voodoos/opam-repository that referenced this pull request May 31, 2023
CHANGES:

unreleased

  + merlin binary
    - Preview support for OCaml 5.1-alpha1. Short path is temporary disabled and
      inline records might not behave as expected.
    - Allow monadic IO in dot protocol (ocaml/merlin#1581)
    - Add a `scope` option to the `occurrences` command in preparation for
      the upcoming `project-wide-occurrences` feature (ocaml/merlin#1596)
    - Construct bool-typed holes as `false` instead of `true` in the
      `construct` command, for consistency (ocaml/merlin#1599).
    - Add a hook to configure system command for spawning ppxes when Merlin is
      used as a library. (ocaml/merlin#1585)
    - Implement an all-or-nothing cache for the PPX phase (ocaml/merlin#1584)
    - Cleanup functors caches when backtracking, to avoid memory leaks
      (ocaml/merlin#1609, fixes ocaml/merlin#1529 and ocaml-lsp#1032)
    - Fix `construct` results ordering for sum types sand poly variants (ocaml/merlin#1603)
    - Fix object method completion not working (ocaml/merlin#1606, fixes ocaml/merlin#1575)
    - Improve context detection for package types (ocaml/merlin#1608, fixes ocaml/merlin#1607)
    - Fix incorrect locations for string literals (ocaml/merlin#1574)
    - Fixed an issue that caused `errors` to erroneously alert about missing
      `cmi` files (ocaml/merlin#1577)
    - Prevent destruct from crashing on closed variant types (ocaml/merlin#1602,
      fixes ocaml/merlin#1601)
    - Improve longident parsing (ocaml/merlin#1612, fixes ocaml/merlin#945)
  + editor modes
    - emacs: call the user's configured completion UI in
      `merlin-construct` (ocaml/merlin#1598)
  + test suite
    - Add missing dependency to a test using ppxlib (ocaml/merlin#1583)
    - Add tests for the new PPX phase cache (ocaml/merlin#1584)
    - Add and update tests for `construct` ordering (ocaml/merlin#1603)
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.

4 participants