emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding support for xref jumping to headers/interfaces


From: Dmitry Gutov
Subject: Re: Adding support for xref jumping to headers/interfaces
Date: Wed, 8 Nov 2023 01:30:09 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0

On 07/11/2023 18:51, Spencer Baugh wrote:

Perhaps it /should/ (xref-find-definitions to include both
implementation and interface). And include the typeDefinition entries
for langs that have those. Etc.

Would the UI be worse? Let's try to find out.

Attached is the patch along the lines that we discussed: a new command
xref-find-extra currently bound to M-' just for the sake of this
experiment (eliminating the need to set up define-key to try out the
"fast" workflow). It uses the symbol at point or asks for it, then
polls the backend for available kinds, does completing-read and asks
the backend for definitions of that kind. And shows the list or jumps
to the unique one.

To have something to test, I implemented this for Elisp. However, all
known kinds are already printed by the regular xref-find-definitions
output in that backend. So the result turned out interesting, but a
little impractical: with Elisp, we already make the choice between the
kinds in the Xref output buffer, when that buffer is shown at all (as
Eli pointed out, actually). So... we could proceed in that direction
and recommend that all kinds of definitions would be added there.

This (and Joao's patch adding support for eglot) is very interesting,
thank you for implementing it!

We also discussed a UI which shows all kinds of definitions in a single
buffer.  Maybe the prompt for KIND should default to "all" which shows
all kinds of definitions?

The natural question is whether 'xref-find-definitions' would be that UI, and if not, why not.

Also, if "references" are included in the list of kinds (as the current patch for Eglot does, I think), then "show all kinds" is not likely to be very useful -- all will drown in "references".

I notice the API doesn't support "fetch all kinds of definitions";
extra-defs requires specifying a specific kind.  Perhaps just specifying
a nil KIND should request all kinds, and extra-defs should tag each
returned object with the kind?  We could also just make a separate call
to extra-defs for each kind returned by extra-kinds, but that would be
allow less space for the backend to batch its operations.

That's a question for later.

Or perhaps the main value would be in actually having separate
commands which could be bound to a submap with faster key sequences
and/or to the context menu (with context-menu-mode on). Then our
solution should be more in line with either defining a number of
additional named commands (for mode universal kinds) and/or making it
easier to define new such commands for users/3rd-party packages/etc.

That's an interesting idea.  So maybe M-' (or whatever) could be a new
prefix for a prefix-map which contains both universal and mode-specific
kinds of lookups.

So maybe something which looks kinda like (not suggesting final
bindings, just trying to feel out what it would be like):

generic eglot-find-implementation:   M-' i
generic eglot-find-declaration:      M-' d
generic eglot-find-typeDefinition:   M-' t

Then we will more-or-less nail down the whole set of "available Xref kinds" in the core by having these commands defined.

That's not very flexible, but if the set doesn't actually change too much, and doesn't vary between languages a lot, it could work. Would lead to a more straightforward design, too.

xref-extra-kind, prompting for kind: M-' M-'

Would we need this command, if we had separate commands for each kind already?

xref-extra-kind, showing all:        M-' a

And if there was something mode-specific, like the Java overriding
method thing, it could be e.g. M-' o

Most of them are mode-specific already. Some languages don't have separate "declarations", some don't know what "type definitions" are, and some, indeed, don't have method overrides.

I like this sort of design a lot actually:

- it's faster to type than having to complete the kind name (IMO, having
   to complete the kind name makes the current patch quite clumsy)
- it allows a common set of keys between all modes
- it's extensible by individual modes without too much trouble
- it works naturally with context-menu-mode and other menus

Indeed.

   (although I suppose we could automatically populate the context-menu
   with the output from xref-backend-extra-kinds)

Probably.

- users could still use completing-read to type the kind

Plus, if we do use M-' or any other short binding for this, we should
almost certainly make it the start of a new prefix-map rather than bind
M-' directly to the new command; doing otherwise would be wasteful of
valuable keybinding space.

If we're going to have separate commands for kinds, that is indeed a good idea.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]