unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dmitry@gutov.dev>
To: Spencer Baugh <sbaugh@janestreet.com>, emacs-devel@gnu.org
Subject: Re: Adding support for xref jumping to headers/interfaces
Date: Thu, 9 Nov 2023 02:08:39 +0200	[thread overview]
Message-ID: <ee5deff0-333b-f85d-1c50-00914dbe2ed6@gutov.dev> (raw)
In-Reply-To: <iero7g4rwbr.fsf@janestreet.com>

On 08/11/2023 19:25, Spencer Baugh wrote:

>>> 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.
> 
> As in, xref-find-definitions (M-.) *by default* shows all kinds of
> definitions?  That seems bad for one big reason: 90% of the time, in 90%
> of languages, there's a clear meaning of "definition" and I want M-. to
> take me there directly rather than prompting in any way.  But there are
> other kinds of "definitions" which plausibly I could want, just
> sometimes, not by default.

Fair enough. So "definitions" are the places we want to see 90% of the 
time when learning about a funciton or a variable. And the other 
reference kinds (BTW, what to call that? "definition kinds"? "reference 
kinds"?) must be apparently less useful.

Do you know which category does "eglot-find-typeDefinition" falls into, 
and why? Aside from the fact that it, historically, uses a separate 
endpoint.

> If you mean something a non-default version of xref-find-definitions, or
> another binding for another basically-identical command, sure, I think
> that would be good.  We can have both that command *and* have a command
> which prompts for KIND and defaults to "all".

We could indeed, if we decide what to call it. "extras" seems out (since 
it would include both definitions and additional reference kinds). Just 
"xref-find-by-kind"? Then it's less obvious to have the default behavior 
showing all.

>> 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".
> 
> True, interesting point.  I wonder if we could reasonably distinguish
> "definition" kinds (a small number per identifier) from "reference"
> kinds (no limit on how many per identifier).

OTOH, maybe "declarations" are a little closer to "references"? E.g. in 
Elisp the declare-function forms seem to be more in that category. And 
if we're talking about C/C++ forward declarations, I suppose that 
depends on whether the declaration is for an "extern"

 > Although I suppose there's
 > also no limit on how many implementations of a generic function there
 > can be, and that's definitely something that fits in "definitions".

The fact that there are often many definitions for a generic function 
indeed is an argument toward including more "kinds" into 
xref-find-definitions' output by default. But only as many as it would 
be actually useful, especially if the kinds are mutually exclusive (a 
symbol is either one or the other) or intersect very rarely, or can be 
distinguished by context.

> Maybe the backend could decide what kinds get included in "all".  Then
> it could deliberately avoid including anything "reference-like".

Could we want several such commands? E.g. one for "all definition-like 
hits" and another for "all reference-like hits"? With separate sets of 
kinds for definitions and references?

>>>> 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.
> 
> Hm, why do you say this?  This approach seems very extensible to me -
> modes could add their own bindings/commands/kinds for things specific to
> that mode.  But they build on top of a set of common kinds which are
> provided by the core, which don't vary between language too much.

It is less flexible because any time a backend wants to use a new 
"kind", it will need to expend some effort and add it to the core 
somehow. Define a new command or two and assign them to the said prefix 
map. This could also lead to conflicts if backend authors don't do this 
carefully enough.

> I do think that if we go with an API which has any notion of "kinds", we
> should have some standard "kinds" in the core like implementation,
> declaration, type-definition.  I don't see any reason not to do that.

We could have a "registry" of kinds, associating each of them with a 
key. Then the result could be more dynamic, e.g. M-' could be bound to a 
command that reads the key and performs the dispatch to the 
corresponding search (similar to project-switch-project).

And the users (though probably not packages) would later be able to 
customize that mapping, adding new kinds or modifying the keys.

With this approach we don't end up with many xref-find-xyz commands, 
most of which just clutter the namespace, staying unused for a large 
proportion of the users. OTOH, one wouldn't be able to examine the 
prefix map and its contents and definitions with (M-' C-h) -- that's a 
minor reduction in usability.

>>> xref-extra-kind, prompting for kind: M-' M-'
>>
>> Would we need this command, if we had separate commands for each kind
>> already?
> 
> This would support kinds which:
> - are language-specific,
> - or are more rarely used and don't need a dedicated command,
> - or are both.

What would be the more frequently used, less language-specific commands?

If we could agree on such list, we could indeed have those 
xref-find-a/b/c definitions and a command with completing-read for the rest.

>>> 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.
> 
> Most languages have something that can fit into "declaration" or "type
> definitions", though.
> 
> For Elisp generics, find-implementation could show the cl-defmethod, and
> find-declaration could jump to the cl-defgeneric.  I would love that,
> actually - I already find it rather annoying to have to navigate in the
> xref buffer to the cl-defgeneric when I M-. on a generic method, if I
> know up front that I want to jump to the cl-defgeneric.

Interesting. I usually find cl-defgeneric entries to be useful in that 
list. But we *are* able to distinguish those that don't contain the 
default implementation.

> Actually, this example has just convinced me that I definitely want
> "kind-specific commands", even for Elisp.  That would be great.
> 
> For functions without separate declarations, find-implementation and
> find-declaration could jump to the same place.  In some languages, maybe
> that's just always what happens.

Aren't find-implementation included in find-definition anyway? Or *are* 
the same as find-definition, for example, in LSP's approach? Aside from 
the fact that the latter also works for variables and other symbols.

> As for type definitions - even Elisp has things that could reasonably be
> called type definitions, we just don't support jump-to-definition for
> them right now.  I have no idea how we'd implement it, but we could
> support jumping to cl-defstruct definitions, for example.  Maybe we
> could use information from native compilation to guess the type of the
> identifier at point?  But anyway, for now we'd just error if the user
> ran such a command in emacs-lisp-mode or other modes that don't support
> jumping to the type definition.

I think the aforementioned type definitions in Elisp would be better 
included in the "find definitions" set because they generally don't 
clash with other kinds.

>>> - 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.
> 
> I almost want to say that we should have it be a prefix regardless of
> whether we have separate commands for kinds.  I guess it depends:

You probably meant "have it be the binding".

> - if we use C-M-?, that's already such a hard key to hit that maybe it's
>    okay if we bind it directly to a command
> 
> - if we use M-' or something similarly convenient, it would be really
>    tragic to not reclaim all that premium keybinding space.

It's possible that it would work better the other way around: if we 
discover that people really want a prefix map, then it would be easier 
to argue for an easy-to-hit binding like the above.

> (And
>    probably if we use M-' we will need to put the old command on
>    something under M-' anyway)

I think it would be odd to put an 'abbrev-...' command inside an 
Xref-specific prefix map. But I suppose reserving the "M-' M-'" sequence 
for this is not out of the question.



  reply	other threads:[~2023-11-09  0:08 UTC|newest]

Thread overview: 204+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-24 19:56 Adding support for xref jumping to headers/interfaces Spencer Baugh
2023-02-24 20:04 ` Eli Zaretskii
2023-02-24 21:29   ` Dmitry Gutov
2023-02-27 23:12     ` Stephen Leake
2023-02-27 23:34       ` Dmitry Gutov
2023-02-28  0:18         ` Yuan Fu
2023-02-28 16:05           ` Filipp Gunbin
2023-03-01  4:33             ` Richard Stallman
2023-03-01 12:50               ` Eli Zaretskii
2023-03-01 17:51                 ` John Yates
2023-03-04 18:54                   ` Stephen Leake
2023-03-04 22:24                     ` Dmitry Gutov
2023-03-05  6:11                       ` Eli Zaretskii
2023-03-05 12:06                         ` Dmitry Gutov
2023-03-07 22:41                           ` Dmitry Gutov
2023-03-08 14:58                             ` Eli Zaretskii
2023-03-08 18:23                               ` Dmitry Gutov
2023-03-08 19:49                                 ` Eli Zaretskii
2023-03-08 20:15                                   ` Dmitry Gutov
2023-03-09  6:13                                     ` Eli Zaretskii
2023-03-09 13:04                                       ` Dmitry Gutov
2023-03-09 15:36                                         ` Eli Zaretskii
2023-03-09 16:53                                           ` Dmitry Gutov
2023-03-09 17:31                                             ` Eli Zaretskii
2023-03-09 17:37                                               ` Dmitry Gutov
2023-05-16 21:10                                                 ` Spencer Baugh
2023-05-17 11:46                                                   ` Eli Zaretskii
2023-06-17  1:53                                                   ` Dmitry Gutov
2023-06-20 15:31                                                     ` João Távora
2023-06-22 19:22                                                       ` Spencer Baugh
2023-06-23  5:52                                                         ` Eli Zaretskii
2023-06-23 14:37                                                           ` Spencer Baugh
2023-06-23 14:53                                                             ` Eli Zaretskii
2023-06-23 15:03                                                         ` João Távora
2023-06-28 13:31                                                           ` Spencer Baugh
2023-11-04 22:43                                                           ` Dmitry Gutov
2023-11-04 22:00                                                       ` Dmitry Gutov
2023-11-04 22:24                                                         ` João Távora
2023-11-04 22:29                                                           ` Dmitry Gutov
2023-11-04 22:36                                                             ` João Távora
2023-11-04 23:20                                                               ` Dmitry Gutov
2023-11-04 23:16                                                   ` Dmitry Gutov
2023-11-04 23:21                                                     ` Dmitry Gutov
2023-11-04 23:24                                                     ` João Távora
2023-11-04 23:27                                                       ` Dmitry Gutov
     [not found]                                                         ` <CALDnm51sWvw4wiipYkJRB8za_8zpWg2-0jpoJDy_5urEa5okzQ@mail.gmail.com>
     [not found]                                                           ` <2752892c-4d27-1249-ca0a-6c24abbf1078@yandex.ru>
     [not found]                                                             ` <CALDnm51P5kfWNofybvxbzVZNnF9DwV5f2ZDGx9ziToBF7cJR6w@mail.gmail.com>
     [not found]                                                               ` <e043f63b-e997-805b-7f9a-64dcc0a9062e@yandex.ru>
     [not found]                                                                 ` <87zfzrybl1.fsf@gmail.com>
     [not found]                                                                   ` <57e53aae-bef9-d267-f7da-d4936fc37153@yandex.ru>
2023-11-07  9:36                                                                     ` João Távora
2023-11-07 22:56                                                                       ` Dmitry Gutov
2023-11-08  0:14                                                                         ` João Távora
2023-11-05  8:16                                                     ` Eshel Yaron
2023-11-07  2:12                                                       ` Dmitry Gutov
2023-11-07 17:09                                                         ` Spencer Baugh
2023-11-07 23:02                                                           ` Dmitry Gutov
2023-11-07 21:30                                                         ` Eshel Yaron
2023-11-07 23:17                                                           ` Dmitry Gutov
2023-11-08  0:21                                                             ` João Távora
2023-11-08  0:33                                                               ` Dmitry Gutov
2023-11-08  1:19                                                                 ` João Távora
2023-11-08 22:58                                                                   ` Dmitry Gutov
2023-11-08 23:22                                                                     ` João Távora
2023-11-08 23:34                                                                       ` Dmitry Gutov
2023-11-09  0:50                                                                         ` João Távora
2023-11-09 16:59                                                                           ` Spencer Baugh
2023-11-09 20:44                                                                             ` João Távora
2023-11-09 21:11                                                                               ` Spencer Baugh
2023-11-10 10:06                                                                                 ` João Távora
2023-11-10 12:02                                                                                   ` Spencer Baugh
2023-11-10 13:59                                                                                     ` João Távora
2023-11-10 17:36                                                                                       ` Spencer Baugh
2023-11-11 10:45                                                                                         ` Dmitry Gutov
2023-11-11 11:17                                                                                         ` João Távora
2023-11-11 12:38                                                                                           ` Spencer Baugh
2023-11-11 20:49                                                                                             ` Dmitry Gutov
2023-11-15 21:32                                                                                               ` Spencer Baugh
2023-11-24  1:37                                                                                                 ` Dmitry Gutov
2023-11-24 21:43                                                                                                   ` Felician Nemeth
2023-11-25  2:20                                                                                                     ` Dmitry Gutov
2023-11-26 16:08                                                                                                       ` Felician Nemeth
2023-11-26 20:15                                                                                                         ` Dmitry Gutov
2023-11-26 20:37                                                                                                           ` João Távora
2023-11-27 14:35                                                                                                             ` Dmitry Gutov
2023-11-27 15:03                                                                                                               ` João Távora
2023-11-27 15:45                                                                                                                 ` Dmitry Gutov
2023-11-27 16:04                                                                                                                   ` João Távora
2023-11-27 16:23                                                                                                                     ` Dmitry Gutov
2023-11-27 16:41                                                                                                                       ` João Távora
2023-11-27 17:05                                                                                                                         ` Dmitry Gutov
2023-11-27 17:09                                                                                                                           ` João Távora
2023-11-26 20:40                                                                                                         ` João Távora
2023-11-27 14:43                                                                                                           ` Dmitry Gutov
2023-11-27 14:49                                                                                                             ` João Távora
2023-11-27 15:01                                                                                                               ` Dmitry Gutov
2023-11-27 15:19                                                                                                                 ` João Távora
2023-11-28  0:18                                                                                                                   ` Dmitry Gutov
2023-11-28  9:51                                                                                                                     ` João Távora
2023-11-28 12:45                                                                                                                       ` Dmitry Gutov
2023-11-28 15:02                                                                                                                         ` João Távora
2023-11-28 16:32                                                                                                                           ` Dmitry Gutov
2023-11-28 17:16                                                                                                                             ` João Távora
2023-11-28 17:25                                                                                                                               ` Dmitry Gutov
2023-11-28 18:38                                                                                                                                 ` João Távora
2023-11-27 15:28                                                                                                                 ` Eli Zaretskii
2023-11-27 16:37                                                                                                                   ` Dmitry Gutov
2023-11-27 16:45                                                                                                                     ` João Távora
2023-11-27 17:40                                                                                                                     ` Eli Zaretskii
2023-11-27 18:26                                                                                                                       ` Dmitry Gutov
2023-11-27 20:50                                                                                                                         ` Eli Zaretskii
2023-11-27 20:53                                                                                                                           ` Dmitry Gutov
2023-11-26 20:30                                                                                                   ` João Távora
2023-11-27 15:17                                                                                                     ` Dmitry Gutov
2023-11-27 15:45                                                                                                       ` João Távora
2023-11-27 16:04                                                                                                         ` Dmitry Gutov
2023-11-27 16:27                                                                                                           ` João Távora
2023-11-27 17:22                                                                                                             ` Dmitry Gutov
2023-11-27 17:46                                                                                                               ` João Távora
2023-11-27 18:12                                                                                                                 ` Dmitry Gutov
2023-11-27 23:25                                                                                                                   ` João Távora
2023-11-28  0:30                                                                                                                     ` Dmitry Gutov
2023-11-28  0:43                                                                                                                       ` João Távora
2023-11-11  1:01                                                                                     ` Dmitry Gutov
2023-11-11  1:04                                                                                   ` Dmitry Gutov
2023-11-11 11:30                                                                                     ` João Távora
2023-11-11 21:01                                                                                       ` Dmitry Gutov
2023-11-12 18:40                                                                                         ` João Távora
2023-11-13  0:27                                                                                           ` Dmitry Gutov
2023-11-13  1:03                                                                                             ` João Távora
2023-11-13  1:05                                                                                               ` Dmitry Gutov
2023-11-13  1:16                                                                                                 ` João Távora
2023-11-13  1:41                                                                                                   ` electric-pair-mode vs paredit, was: " Dmitry Gutov
2023-11-13  1:53                                                                                                     ` João Távora
2023-11-11  0:58                                                                               ` Dmitry Gutov
2023-11-11 11:44                                                                                 ` João Távora
2023-11-11 21:37                                                                                   ` Dmitry Gutov
2023-11-12 18:59                                                                                     ` João Távora
2023-11-13  1:37                                                                                       ` Dmitry Gutov
2023-11-11  1:08                                                                               ` Dmitry Gutov
2023-11-11 11:22                                                                                 ` João Távora
2023-11-11 20:54                                                                                   ` Dmitry Gutov
2023-11-08 16:11                                                               ` Spencer Baugh
2023-11-08 17:20                                                                 ` João Távora
2023-11-08 17:40                                                                   ` Spencer Baugh
2023-11-08 23:08                                                                     ` João Távora
2023-11-09 16:52                                                                       ` CCing thread participants through gnus+gmane Spencer Baugh
2023-11-10 15:51                                                                         ` Eric Abrahamsen
2023-11-10 16:18                                                                         ` Visuwesh
2023-11-09 17:07                                                                       ` Adding support for xref jumping to headers/interfaces Spencer Baugh
2023-11-11  0:07                                                                         ` Dmitry Gutov
2023-11-11 12:39                                                                           ` Spencer Baugh
2023-11-11 20:45                                                                             ` Dmitry Gutov
2023-11-08 23:06                                                                 ` Dmitry Gutov
2023-11-07 16:51                                                     ` Spencer Baugh
2023-11-07 23:30                                                       ` Dmitry Gutov
2023-11-08 17:25                                                         ` Spencer Baugh
2023-11-09  0:08                                                           ` Dmitry Gutov [this message]
2023-11-09  0:26                                                             ` Dmitry Gutov
2023-11-09  1:06                                                               ` João Távora
2023-11-11  0:16                                                                 ` Dmitry Gutov
2023-11-09 17:57                                                             ` Spencer Baugh
2023-11-11  0:42                                                               ` Dmitry Gutov
2023-11-11 13:00                                                                 ` Spencer Baugh
2023-11-12  1:50                                                                   ` Dmitry Gutov
2023-11-12  2:08                                                                     ` João Távora
2023-11-12  2:09                                                                       ` Dmitry Gutov
2023-11-12  2:25                                                                         ` João Távora
2023-11-13  1:02                                                                           ` Dmitry Gutov
2023-11-13  1:24                                                                             ` João Távora
2023-03-01 15:00               ` [External] : " Drew Adams
2023-02-28 21:40           ` John Yates
2023-02-28 21:53             ` Dmitry Gutov
2023-02-28 22:44               ` Konstantin Kharlamov
2023-03-05  9:59 ` Helmut Eller
2023-03-05 12:03   ` Dmitry Gutov
2023-03-05 15:57     ` Helmut Eller
2023-03-05 16:33       ` Dmitry Gutov
2023-03-05 17:19         ` Stephen Leake
2023-03-05 20:10   ` João Távora
2023-03-05 20:32     ` João Távora
2023-03-05 20:40       ` Dmitry Gutov
2023-03-05 21:04         ` João Távora
2023-03-05 21:21           ` Dmitry Gutov
2023-03-05 21:48             ` João Távora
2023-03-05 22:08               ` Dmitry Gutov
2023-03-05 23:00                 ` João Távora
2023-03-05 23:40                 ` John Yates
2023-03-06 12:22                   ` Felician Nemeth
2023-03-06 13:15                     ` João Távora
2023-03-06 13:23                       ` Dmitry Gutov
2023-03-06 13:38                         ` João Távora
2023-03-06 13:46                           ` Dmitry Gutov
2023-03-06 13:52                             ` João Távora
2023-03-06 13:50                           ` Dmitry Gutov
2023-03-07  7:15                             ` Yuan Fu
2023-03-07 19:58                               ` Felician Nemeth
2023-03-07 20:44                                 ` Yuan Fu
2023-03-07 21:03                                 ` Dmitry Gutov
2023-03-06 14:09                   ` Dmitry Gutov
2023-03-06 14:15                     ` John Yates
2023-03-06 14:23                       ` Dmitry Gutov
2023-03-06 14:43                         ` John Yates
2023-03-10  0:57                     ` Ergus
2023-03-10 21:55                       ` Dmitry Gutov
2023-03-10 22:18                         ` João Távora
2023-03-10 22:25                           ` Dmitry Gutov
2023-03-11 11:50                             ` João Távora
2023-03-10 23:45                         ` Ergus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ee5deff0-333b-f85d-1c50-00914dbe2ed6@gutov.dev \
    --to=dmitry@gutov.dev \
    --cc=emacs-devel@gnu.org \
    --cc=sbaugh@janestreet.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).