Skip to content

Conversation

@mattiase
Copy link
Contributor

Fix uses of Xref from mouse events, such as the context menu new in Emacs 28, by implementing the necessary methods and smuggle the buffer position in a text property of the string.

We also get better highlighting of Xref hits in the target buffer by taking advantage of a bug fixed in Emacs 28.

@mattiase
Copy link
Contributor Author

mattiase commented Oct 5, 2021

With the last part of this PR, xref can now more easily be used for looking up definitions and occurrences of operators.

@voodoos
Copy link
Collaborator

voodoos commented Mar 28, 2022

@rgrinberg I requested your review since you appear to be the author of the initial xref support.

@rgrinberg
Copy link
Member

I don't use any Emacs anymore and don't remember much of elisp. I think we need to find someone else to review unfortunately.

@rgrinberg rgrinberg removed their request for review March 28, 2022 19:06
@mattiase
Copy link
Contributor Author

mattiase commented Apr 6, 2022

Tell me if there is anything more I should do with the patch set. I did consult the author of the Xref facility in Emacs for how best to use the interface in a way that's compatible with different versions.

@bbatsov
Copy link

bbatsov commented Jun 21, 2022

The changes look good to me.

Allow xref operations initiated from a mouse click to work correctly
by encoding the location of a selected identifier in a string property
on that identifier.
Use `xref-file-location` instead of `xref-buffer-location` since the
former gives line numbers and nicer display when there are multiple
matches on the same line.  Since Emacs 28, we have to partition the
line when populating the `summary` field.
Use the `match` face for highlighting if `xref-match` isn't
available (for Emacs 26 or older).
This will be used for `xref-find-references` (`M-?`), although that
command currently ignores the string and only uses the location.

If an identifier both succeeds and precedes point, prefer the former.
For instance, in `a+b` with the cursor on `+`, use `+` as the
idenfier; with the cursor on `b`, use `b`.
For some reason, the occurrences command output sometimes contains
bogus locations (line 0, col -1). It really shouldn't, but filter
them out until that has been fixed (ocaml#1410).
@mattiase
Copy link
Contributor Author

Not sure what this patch is waiting for – all rather straightforward things I thought. Anyway, it's up to date with master.

@bbatsov
Copy link

bbatsov commented Dec 22, 2022

@rgrinberg Can you help us to get this merged?

@voodoos
Copy link
Collaborator

voodoos commented Dec 22, 2022

Thanks for your review @bbatsov, and @mattiase for rebasing the PR. Sorry it took so long.

@mattiase could you add a changelog entry for this one ? Thank you !

@mattiase
Copy link
Contributor Author

@mattiase could you add a changelog entry for this one ?

Done.

@voodoos voodoos merged commit 41cd949 into ocaml:master Dec 22, 2022
@mattiase mattiase deleted the xref branch December 22, 2022 12:44
voodoos added a commit to voodoos/merlin that referenced this pull request Feb 22, 2023
voodoos added a commit to voodoos/opam-repository that referenced this pull request Feb 24, 2023
CHANGES:

Fri Feb 24 16:55:42 CEST 2023

  + merlin binary
    - Recognize OCaml 5.0 cmi magic number in compiler version mismatch message
      (ocaml/merlin#1554, fixes ocaml/merlin#1553)
    - Upgrade Merlin from the RC2 to the stable 5.0.0 compiler release (ocaml/merlin#1559,
      fixes ocaml/merlin#1558)
    - Improve type-enclosing behaviour when used on records' labels (ocaml/merlin#1565,
      fixes ocaml/merlin#1564)
    - Restore compatibility with the compiler's command line by accepting the
      `-safe-string` flag as a no-op instead of rejecting it (ocaml/merlin#1544, fixes
      ocaml/merlin#1518)
    - Traverse aliases when jumping to declaration. This matches
      jump-to-definition's behavior (ocaml/merlin#1563)
    - Improve locate's behavior in various ill-typed expressions (ocaml/merlin#1546, fixes
      ocaml/merlin#1567 and partially ocaml/merlin#1543)
    - Correctly traverse patterns when looking for docs in the typedtree (ocaml/merlin#1572)
    - Get documentation when the declaration or definition is selected (ocaml/merlin#1542,
      fixes ocaml/merlin#1540)
    - On Windows, change to a harmless directory when launching server to avoid
      locking down current directory (ocaml/merlin#1569, fixes ocaml/merlin#1474)
  + editor modes
    - emacs: Fix misuse of `eq` comparison (ocaml/merlin#1549, @mattiase)
    - emacs: xref works from context menus; better highlighting of xref matches;
      xref recognises operators and binding operators at the cursor position;
      bad locations are filtered out (ocaml/merlin#1385, fixes ocaml/merlin#1410, @mattiase)
  + test suite
    - Add a test for incorrect alert defaults (ocaml/merlin#1559)
    - Add multiple tests for locate over ill-typed expressions (ocaml/merlin#1546)
    - Add non-regression tests for other fixes in this release
voodoos added a commit to voodoos/opam-repository that referenced this pull request Feb 24, 2023
CHANGES:

Fri Feb 24 16:55:42 CEST 2023

  + merlin binary
    - Recognize OCaml 5.0 cmi magic number in compiler version mismatch message
      (ocaml/merlin#1554, fixes ocaml/merlin#1553)
    - Upgrade Merlin from the RC2 to the stable 5.0.0 compiler release (ocaml/merlin#1559,
      fixes ocaml/merlin#1558)
    - Improve type-enclosing behaviour when used on records' labels (ocaml/merlin#1565,
      fixes ocaml/merlin#1564)
    - Restore compatibility with the compiler's command line by accepting the
      `-safe-string` flag as a no-op instead of rejecting it (ocaml/merlin#1544, fixes
      ocaml/merlin#1518)
    - Traverse aliases when jumping to declaration. This matches
      jump-to-definition's behavior (ocaml/merlin#1563)
    - Improve locate's behavior in various ill-typed expressions (ocaml/merlin#1546, fixes
      ocaml/merlin#1567 and partially ocaml/merlin#1543)
    - Correctly traverse patterns when looking for docs in the typedtree (ocaml/merlin#1572)
    - Get documentation when the declaration or definition is selected (ocaml/merlin#1542,
      fixes ocaml/merlin#1540)
    - On Windows, change to a harmless directory when launching server to avoid
      locking down current directory (ocaml/merlin#1569, fixes ocaml/merlin#1474)
  + editor modes
    - emacs: Fix misuse of `eq` comparison (ocaml/merlin#1549, @mattiase)
    - emacs: xref works from context menus; better highlighting of xref matches;
      xref recognises operators and binding operators at the cursor position;
      bad locations are filtered out (ocaml/merlin#1385, fixes ocaml/merlin#1410, @mattiase)
  + test suite
    - Add a test for incorrect alert defaults (ocaml/merlin#1559)
    - Add multiple tests for locate over ill-typed expressions (ocaml/merlin#1546)
    - Add non-regression tests for other fixes in this release
voodoos added a commit to voodoos/merlin that referenced this pull request May 2, 2024
voodoos added a commit to voodoos/merlin that referenced this pull request May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants