* xref-find-references returns duplicates
@ 2022-12-19 0:25 Petteri Hintsanen
2022-12-27 1:09 ` Dmitry Gutov
0 siblings, 1 reply; 3+ messages in thread
From: Petteri Hintsanen @ 2022-12-19 0:25 UTC (permalink / raw)
To: help-gnu-emacs
Hello list,
I discovered a somewhat peculiar case where xref-find-references returns
duplicate references for elisp symbols.
Here is a toy example:
1. Create a file ~/foo/bar/bar.el with contents:
(defun bar-f ())
(defun bar-g ()
(bar-f))
(provide 'bar)
2. Create a git repo in ~/foo/bar and commit bar.el. This is just to
set up a project that Emacs can recognize.
3. Start emacs -Q and eval
(add-to-list 'load-path "~/foo")
(add-to-list 'load-path "~/foo/bar")
(require 'bar)
4. Visit ~/foo/bar/bar.el and do xref-find-references for bar-f
On my machine I get
bar.el
1: (defun bar-f ())
4: (bar-f))
1: (defun bar-f ())
4: (bar-f))
i.e. references are duplicated. The issue seems to be in load-path: if
I remove ~/foo from step (3) above, then I don't see any duplicates.
Am I abusing load-path somehow, or is this a bug, or something else?
Emacs version is 28.2, running on Debian.
(The real use case is elisp directory hierarchy like this
~/elisp/
~/elisp/package-a/
~/elisp/package-b/
~/elisp/package-c/
...
where package dirs are checkouts from various repositories, and all
directories are added to load-path. ~/elisp/ has miscellaneous files
which do not belong to any package. I guess I could work around this
just by putting them to ~/elisp/etc/ or something, but I'd like to know
why xref works here like it does.)
Thanks,
Petteri
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: xref-find-references returns duplicates
2022-12-19 0:25 xref-find-references returns duplicates Petteri Hintsanen
@ 2022-12-27 1:09 ` Dmitry Gutov
2022-12-27 15:46 ` Petteri Hintsanen
0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Gutov @ 2022-12-27 1:09 UTC (permalink / raw)
To: Petteri Hintsanen, help-gnu-emacs
On 19/12/2022 02:25, Petteri Hintsanen wrote:
> Hello list,
>
> I discovered a somewhat peculiar case where xref-find-references returns
> duplicate references for elisp symbols.
>
> Here is a toy example:
>
> 1. Create a file ~/foo/bar/bar.el with contents:
>
> (defun bar-f ())
>
> (defun bar-g ()
> (bar-f))
>
> (provide 'bar)
>
> 2. Create a git repo in ~/foo/bar and commit bar.el. This is just to
> set up a project that Emacs can recognize.
>
> 3. Start emacs -Q and eval
>
> (add-to-list 'load-path "~/foo")
> (add-to-list 'load-path "~/foo/bar")
> (require 'bar)
>
> 4. Visit ~/foo/bar/bar.el and do xref-find-references for bar-f
>
> On my machine I get
>
> bar.el
> 1: (defun bar-f ())
> 4: (bar-f))
> 1: (defun bar-f ())
> 4: (bar-f))
>
> i.e. references are duplicated. The issue seems to be in load-path: if
> I remove ~/foo from step (3) above, then I don't see any duplicates.
>
> Am I abusing load-path somehow, or is this a bug, or something else?
I suppose it's a bug, or a limitation of the algorithm anyway.
The default "find references" implementation currently delegates to
xref-references-in-directory, which uses the semantic-symref-tool
facility to search for a simple notion of "references" inside a
directory tree. It doesn't have a mechanism to exclude certain
directories, such as the current project root (from being searched twice
over).
You can file a bug report with 'M-x report-emacs-bug', different ways to
solve this exist, more or less adequately.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: xref-find-references returns duplicates
2022-12-27 1:09 ` Dmitry Gutov
@ 2022-12-27 15:46 ` Petteri Hintsanen
0 siblings, 0 replies; 3+ messages in thread
From: Petteri Hintsanen @ 2022-12-27 15:46 UTC (permalink / raw)
To: help-gnu-emacs
Dmitry Gutov <dgutov@yandex.ru> writes:
> I suppose it's a bug, or a limitation of the algorithm anyway.
Ok, thanks for explanation. As a workaround, I moved files from the
parent directory into their own subdirectory, and added that to
load-path instead of the parent dir. I can easily live with this.
> You can file a bug report with 'M-x report-emacs-bug', different ways
> to solve this exist, more or less adequately.
Very well, I'll file a bug soon-ish.
Thanks,
Petteri
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-12-27 15:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-19 0:25 xref-find-references returns duplicates Petteri Hintsanen
2022-12-27 1:09 ` Dmitry Gutov
2022-12-27 15:46 ` Petteri Hintsanen
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.