emacs-devel
[Top][All Lists]
Advanced

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

Re: xref-query-replace-in-results error message after xref-find-definiti


From: Dmitry Gutov
Subject: Re: xref-query-replace-in-results error message after xref-find-definitions, was: Re: bug#58158: 29.0.50; [overlay] Interval tree iteration considered harmful
Date: Tue, 11 Oct 2022 19:41:35 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2

On 11.10.2022 19:01, Eli Zaretskii wrote:

So maybe just saying

    Cannot do global replacement using results of \\[xref-find-definitions]

should be okay?

Isn't it almost the same as I suggested upthread? Except I suggested
"this search" instead of naming the specific command.

I'm not trying to argue, I'm trying to find the best message text.  It
doesn't matter who suggested it first, what matters whether it is
accurate and self-explanatory.

I wasn't playing "who said it first" either, but pointing at the previous suggestion as a little more inherently-accurate.

Do you think naming it will be helpful enough to sacrifice the 10%
accuracy of the message? I suppose someone might have indeed forgotten
that they did the search using xref-find-definitions.

What are the 10% of inaccuracy?

Sorry, losing 100% accuracy, to get a slightly smaller percentage.

If the message will only ever be
shown when 'r' is invoked after M-., then what is inaccurate in it?

Almost only ever. With potential for exceptions, unless we try to enforce their absence.

That would mean that one 'r' can work in lsp-mode's
xref-find-definitions results (they define a bunch of custom commands
like lsp-find-definition and lsp-find-declaration, but that probably
doesn't matter). Not sure if we should do something about that.

If 'r' happens to work in that case, we don't have to worry about the
error message, right?

That's correct, but having the command succeed might be a problem by
itself, couldn't it? It will rename the definitions (and/or
declarations), but not other occurrences.

No error message could possibly prevent that from happening, could it?

Only if it happens somewhere else, or if the check before the errors is changed significantly.

If we go in from this direction, we can have
xref-show-definitions-buffer (the default
xref-show-definitions-function) ensure that the binding for 'r' is set
to some command that always reports an error (like 'cannot replace in
definitions'), or is unbound.

But users can always invoke the command by name as well.

That's, uh, true. But having commands intended for one major mode silently failing (or doing that in a weird fashion) when invoked with 'M-x' in another major mode has not usually been a concern for us.

This would do nothing for custom values of
xref-show-definitions-function, but should remove most of the confusion
with default configuration. And some non-default ones as well (lsp-mode
doesn't change the value of xref-show-definitions-function).

If the docstring of xref-show-definitions-function looks okay to you, we
can use its vocabulary.

    Cannot replace in definition search results

should cover xref-find-definitions, lsp-find-definition and
lsp-find-declaration. Wouldn't help with lsp-find-implementation, though
(its results are also questionable WRT renaming because they don't
include all references either), but it won't make it worse.

Hmm... maybe

   Cannot perform global replacement in find-definition results

Another idea would be for the error message to be constructed
dynamically, and include the precise command that produced the Xref
buffer, if xref.el could record that in some buffer-local variable.

I suppose it could. But then some backend (such as lsp or possibly eglot) might return 'definitions' results in format suitable for replacements, and that will mean that one can replace in xref-find-definitions's results, just with some backends but not others.

And with that, the error message

  Cannot do global replacement using results of \\[xref-find-definitions]

shown to the same user at a different time (perhaps when they're editing Elisp) will become a lie.

And then, okay, we could try to add the name of the backend symbol to the error message as well, but it's much harder to capture that one, especially given that not every command using Xref output will go through xref-backend-functions (project-find-regexp is a counter-example).



reply via email to

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