unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: "João Távora" <joaotavora@gmail.com>, emacs-devel <emacs-devel@gnu.org>
Subject: Re: Adding support for xref jumping to headers/interfaces
Date: Wed, 8 Nov 2023 00:56:30 +0200	[thread overview]
Message-ID: <32b50454-2e9d-f7f4-1841-7f2571bfa9b2@yandex.ru> (raw)
In-Reply-To: <CALDnm50kvnrmoYoueXOT3t+GAPhD+HAT4ZLrZehoYZS8BRQrAg@mail.gmail.com>

On 07/11/2023 11:36, João Távora wrote:
> [Adding back emacs-devel, which I didn't mean to remove from my previous
> email.  This is also why I quote your message fully.  ]

Perfect.

>>> It wasn't very difficult, but I did have to scratch my head a bit until
>>> I found what I think is the key.  So first I did a reasonably simple
>>> commit to xref.el, which gives xref-find-extra a KIND argument, making
>>> it more versatile since it can now be used non-interactively.  I think
>>> the interactive behavior is completely unchanged.  The docstring might
>>> need a tweak or two.
>>
>> There is an omission in being able to input the identifier (fixable, of
>> course).
> 
> Can you explain exactly the problem?  I'm happy to fix it.

Just that it does not ask for the identifier (with C-u or without); that 
it cannot. But if that won't be useful anyway (as you state below), 
there's no point in trying.

>> Though I'm not sure if that capability will be helpful for
>> those searches with an LSP client (with language servers providing
>> relatively limited identifier completion).
> 
> Indeed, it's not.  For every reference kind _except_ the "definition"
> kind, where it does come in handy, since I have a hack for that
> too.  Indeed very handy (and very hackish, but that's life).

So... there's no way to take a "definition" symbol name (and associated 
metadata) and jump to the "declaration", for example? Using that hack of 
yours, or with a slight tweak.

>> I still note, though, that you kept those commands around:
>> eglot-find-declaration/implementation/typeDefinition. Whereas previously
>> I seem to recall you opined that the commands themselves shouldn't be in
>> Eglot.
>>
>> Would you say it's a backward compatibility concern, or something else
>> as well?
> 
> The former.  IOW if xref.el had this capability in the past, I would have
> used it.
> 
> But I still nonetheless think functions should be as versatile as possible,
> so that even what we designed as an interactive entry-point can be used
> as a library entry point.

Well, making those commands easy to write is a small task. We already 
have 'xref-show-xrefs' which you could call, and if my thinking is right 
(the bottom of the previous email), a new function called 
'xref-show-defs' which internally uses xref-show-definitions-function, 
would be just what the doctor ordered. No new backend methods necessary.

>>> Anyway, this new xref-find-extra aided greatly in adding Eglot support.
>>> It removes the need for a very hackish implementation of the existing
>>> 'eglot-find-declaration', 'eglot-find-implementation' and
>>> 'eglot-find-typeDefinition' commands.  And of course 'xref-find-extra'
>>> as an interactive entry point also works for finding these things.
>>
>> Whatever solution we decide to go with in the end, it should be
>> straightforward enough to create a helper that would assist in defining
>> such commands.
> 
> Yes.  I do think this one is pretty good at doing that.  But I guess
> even with this one, you could offer a 'xref-define-interactive-finder-for-kind'
> macro that would automate it even further and help xref.el retain finer
> control over how exactly that finder behaves, for example vis-a-vis
> prefix arguments.

Right. Though if the backend cannot work on arbitrary symbol names (only 
on symbol at point), that kind of negates most of the benefits.

>>> One thing that is missing IMO, but is reasonably easy to fix, is an
>>> indirection to allow non-string objects to be used as KIND, but still
>>> have these objects be displayed to the user with a pretty string.  Of
>>> course, this is not essential -- I could just use strings as KINDs in
>>> eglot.el and be done with it -- but I feel it'd be a little nicer.
>>> Right now I'm using the symbols 'eglot--xref-implementation',
>>> 'eglot--xref-declaration', etc, which are printed as is to the user in
>>> the completing-read of 'xref-find-extra'.  Works for now.
>>
>> Using strings as KINDs is what allows us to use completing-read on them.
>> Internally, there could be of course some alist mapping them to complex
>> objects. If you have a better idea, I'm open.
> 
> Yes, that indirection is what is needed.  It could be done via symbol
> properties (in which case KIND would be a symbol or a string), via
> a specific prescription that KIND can be (OBJ . DISPLAY), a specific
> prescription like (OBJ . DISPLAY-FN-TO-BE-CALLED-ON-OBJ) or just a
> generic function whose default implementation is #'identity thus
> letting completing read do whatever it does for that OBJ, which in
> the case of symbols is convert them to string and return that string).
> Very many ways to skin this cat, so just pick one.

I suppose xref-backend-definition-kinds could return any data structure 
that completing-read could use? A.g. an alist.

> But just to be clear: whatever the technique used, that "mapping" you
> speak of (which I call "indirection"), could _not_ be "internal".  It
> would have to be exposed so the backend can control how the OBJs it
> returns from 'xref-backend-extra-kinds' are converted to strings.

Hm, why not? You set up an internal var with the mapping, return a list 
of strings, get one of those stings, look up the "complex" var in the 
mapping, and use it. Text properties are a good option too, but IIRC 
there was a problem with completing-read stripping them.

>>> Another idea I had while doing this is that the name xref-find-extra
>>> could be actually something like xref-find-by-kind.  What I mean is that
>>> I found myself adding the existing kinds "definition" and "references"
>>> to that "extra" set.  I think this is more comfortable for the user that
>>> even though they are not "extras".
>>
>> This is one of the questions I'd like to see answered:
>>
>> - Should a command like this include existing kinds (that
>> xref-find-definitions already lists)?
> 
> My answer is yes.  But we could leave that up to the backend.

We would ultimately leave it all to the backend, of course, but we 
should provide some guidelines. And these choices should inform the 
commands we add and how we organize them.

> I
> intend to remap M-?  to xref-find-extra myself, losing the speed of
> xref-find-references for "all references", but gaining in versatility.
> Of course a similar effect could be achieved via some kind of prefix
> argument or variable controlling the behaviour of xref-find-references.
 >
> Another thing that I think should be changed is the name of the generic
> function xref-backend-extra-defs.  It should be IMO xref-backend-extra-refs
> because a "definition" is a type of "reference" to a symbol/name.  Likewise
> to mentions of "definition" in the new docstrings.

We use xref-show-xrefs-function for "references" and 
xref-show-definitions-function for "definitions". By default they differ 
in what happens if there is just 1 match (the latter just jumps to it). 
But one can also customize xref-show-definitions-function to 
xref-show-definitions-completing-read (which I did), and then you get a 
direct jump (with completion) for definitions, and a list of all matches 
for references. A definition could be called a subtype of a reference, 
but they often carry different information in practice as well.

Perhaps we could add two commands: xref-find-defs-by-kind and 
xref-find-xrefs-by-kind. I wonder which "kinds" would get sorted in the 
second category along with "references", though.

>> - Should there be other kinds in it, absent from xref-find-definitions?
>> If yes, of kinds of "kinds" (:-)) should be in one set but not the other?
> 
> Up to the backend.
> 
>> - Should xref-find-definitions include the results of
>> eglot-find-declaration and eglot-find-typeDefinition? Does it include
>> them already?
> 
> That's up to the backend, Eglot in this case.  And the Eglot backend
> leaves that up to the LSP server, so it's a question that can't be answered.

Eglot could make several queries and append the results. It might be 
slower in certain cases, but I'm not sure it will be slow enough for the 
users to take notice. In most cases, anyway.

That might lead to a better UX as well. For example, what kind of 
symbols does eglot-find-typeDefinition work on? Type references? If you 
invoke xref-find-definitions instead, does it find any other kind of 
definitions for them?

Speaking of guidelines and semantics again:

1. If we were to expect that "xref-find-definitions" finds all kinds of 
definitions, we could instead just add a new method to xref-item to 
indicate kind. And then filter. Theoretically less efficient, but if 
xref-find-definitions will remain the main tool for people, saving on 
work in rare situations might not be optimal.

2. If we say that xref-find-extra includes kinds that are already in 
"definitions", then the name "extra" is invalid, and 
xref-find-...-by-kind seems more apt as the name of a command. If it 
only included "extra" kinds, OTOH, the names would hold.

3. If xref-find-...-by-kind allows you to find both kinds included in 
the set of "definitions" and not, that becomes the most awkward option 
to describe, in the docstrings and the manual. In any case, we'd have to 
use the most careful naming.



  reply	other threads:[~2023-11-07 22:56 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 [this message]
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
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=32b50454-2e9d-f7f4-1841-7f2571bfa9b2@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    --cc=joaotavora@gmail.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).