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

Improve context detection for infix operators #1756

Merged
merged 3 commits into from
May 2, 2024

Conversation

voodoos
Copy link
Collaborator

@voodoos voodoos commented May 2, 2024

Context detection for longidents relies on some britle "where is the cursor in the lid" logic.
This PR add a special case to improve the handling of operators that requires parenthesis.
More precise locations in lid is required to actually get a clean and correct implementation, but at least this PR improves the situation a bit.

Comment on lines +70 to +71
(* FIXME: this is britle, but lids don't have precise enough location
information to handle these cases correctly. *)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is brittle. But in fact, is that really brittle?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, the whole thing is a bit dodgy. Merlin reconstructs a string, that it then parses again, to try to guess on what component the cursor here since longident don't have precise enough location information. Mixed with weird things like ident that require parenthesis or others that require parenthesis plus spaces, it makes the whole process very hacky.

Hopefully having better location information in longidents will allow us to replace all of this soon :-)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Make sense. Thanks for the explanation!

@voodoos voodoos force-pushed the improve-context-detection branch from 3024444 to b551ab2 Compare May 2, 2024 14:31
It's always correct to have a space after the parenthesis and it is sometimes
necessary, for infix operators that start with `*` for example.
@voodoos voodoos force-pushed the improve-context-detection branch from b551ab2 to 9f8cbf4 Compare May 2, 2024 14:32
@voodoos voodoos merged commit 2eeb9be into ocaml:master May 2, 2024
11 of 12 checks passed
voodoos added a commit to voodoos/merlin that referenced this pull request May 13, 2024
Improve context detection for infix operators
voodoos added a commit to voodoos/opam-repository that referenced this pull request May 17, 2024
CHANGES:

Fri May 17 19:59:42 CET 2024

  + merlin binary
    - Support for OCaml 5.2 (ocaml/merlin#1757)
    - destruct: Removal of residual patterns (ocaml/merlin#1737, fixes ocaml/merlin#1560)
    - Do not erase fields' names when destructing punned record fields (ocaml/merlin#1734,
      fixes ocaml/merlin#1661)
    - Ignore SIGPIPE in the Merlin server process (ocaml/merlin#1746)
    - Fix lexing of quoted strings in comments (ocaml/merlin#1754, fixes ocaml/merlin#1753)
    - Improve cursor position detection in longidents (ocaml/merlin#1756)
    - Addition of a `merlin-lib.commands` library which disassociates the
      execution of commands from the `new_protocol`, from the binary, allowing
      it to be invoked from other projects (ocaml/merlin#1758)
    - New occurrences backend: Don't index occurrences when `merlin.hide`
      attribute is present. (ocaml/merlin#1768)
    - Use the new `uid_to_decl` table in 5.2's cmt files to get documentation.
      (ocaml/merlin#1773)
voodoos added a commit to voodoos/opam-repository that referenced this pull request May 31, 2024
CHANGES:

May May 31 14:02:42 CET 2024

  + merlin binary
    - destruct: Removal of residual patterns (ocaml/merlin#1737, fixes ocaml/merlin#1560)
    - Do not erase fields' names when destructing punned record fields (ocaml/merlin#1734,
      fixes ocaml/merlin#1661)
    - Ignore SIGPIPE in the Merlin server process (ocaml/merlin#1746)
    - Fix lexing of quoted strings in comments (ocaml/merlin#1754, fixes ocaml/merlin#1753)
    - Improve cursor position detection in longidents (ocaml/merlin#1756)
voodoos added a commit to voodoos/opam-repository that referenced this pull request May 31, 2024
CHANGES:

Fri May 31 14:02:42 CEST 2024

  + merlin binary
    - destruct: Removal of residual patterns (ocaml/merlin#1737, fixes ocaml/merlin#1560)
    - Do not erase fields' names when destructing punned record fields (ocaml/merlin#1734,
      fixes ocaml/merlin#1661)
    - Ignore SIGPIPE in the Merlin server process (ocaml/merlin#1746)
    - Fix lexing of quoted strings in comments (ocaml/merlin#1754, fixes ocaml/merlin#1753)
    - Improve cursor position detection in longidents (ocaml/merlin#1756)
voodoos added a commit to voodoos/opam-repository that referenced this pull request May 31, 2024
CHANGES:

Fri May 31 14:02:42 CEST 2024

  + merlin binary
    - destruct: Removal of residual patterns (ocaml/merlin#1737, fixes ocaml/merlin#1560)
    - Do not erase fields' names when destructing punned record fields (ocaml/merlin#1734,
      fixes ocaml/merlin#1661)
    - Ignore SIGPIPE in the Merlin server process (ocaml/merlin#1746)
    - Fix lexing of quoted strings in comments (ocaml/merlin#1754, fixes ocaml/merlin#1753)
    - Improve cursor position detection in longidents (ocaml/merlin#1756)
voodoos added a commit to voodoos/opam-repository that referenced this pull request May 31, 2024
CHANGES:

Fri May 31 14:02:42 CEST 2024

  + merlin binary
    - destruct: Removal of residual patterns (ocaml/merlin#1737, fixes ocaml/merlin#1560)
    - Do not erase fields' names when destructing punned record fields (ocaml/merlin#1734,
      fixes ocaml/merlin#1661)
    - Ignore SIGPIPE in the Merlin server process (ocaml/merlin#1746)
    - Fix lexing of quoted strings in comments (ocaml/merlin#1754, fixes ocaml/merlin#1753)
    - Improve cursor position detection in longidents (ocaml/merlin#1756)
avsm pushed a commit to avsm/opam-repository that referenced this pull request Sep 5, 2024
CHANGES:

Fri May 31 14:02:42 CEST 2024

  + merlin binary
    - destruct: Removal of residual patterns (ocaml/merlin#1737, fixes ocaml/merlin#1560)
    - Do not erase fields' names when destructing punned record fields (ocaml/merlin#1734,
      fixes ocaml/merlin#1661)
    - Ignore SIGPIPE in the Merlin server process (ocaml/merlin#1746)
    - Fix lexing of quoted strings in comments (ocaml/merlin#1754, fixes ocaml/merlin#1753)
    - Improve cursor position detection in longidents (ocaml/merlin#1756)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 5.0-501
Development

Successfully merging this pull request may close these issues.

2 participants