cider icon indicating copy to clipboard operation
cider copied to clipboard

cider--xref-backend returns incorrect relative filenames for references

Open shashurup opened this issue 3 years ago • 12 comments

Expected behavior

xref-find-references with cider backend must return either absolute file name or the name relative to the file of the current buffer.

Actual behavior

the file name returned is realtive to src directory and, as a result, selecting a reference in xref buffer doesn't work.

Steps to reproduce the problem

Put a cursor to some function in a clojure buffer, invoke xref-find-references. Try to select some of the candidates in the xref window.

Environment & Version information

CIDER version information

;; CIDER 1.2.0snapshot (package: 20211215.925), nREPL 0.9.0-beta5
;; Clojure 1.10.3, Java 11.0.13

Emacs version

GNU Emacs 27.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.27, cairo version 1.17.4) of 2021-03-26

Operating system

Arch Linux

shashurup avatar Dec 25 '21 11:12 shashurup

Hi! Thanks for the report.

Can you please also include one of the (presumed) problematic filenames?

vemv avatar Dec 25 '21 11:12 vemv

Sure, https://github.com/shashurup/feedcircuit-revisited/blob/19ecd0057abe7edff4aea82279e3f425914c6c0c/src/feedcircuit_revisited/backend.clj#L68 Just try to find references to get-unread-items, there is one in ui.clj

shashurup avatar Dec 25 '21 11:12 shashurup

I meant, what exact value is CIDER handling that you believe is problematic.

When you say the file name returned is relative to src directorywe'd prefer to see a specific string

vemv avatar Dec 25 '21 11:12 vemv

aha, ok in my case for "get-unread-items" the file name "feedcircuit-revisited/ui.clj" is returned but for the xref window the default directory is .../src/feedcircuit-revisited and when I select a candidate it attempts to open .../src/feedcircuit-revisited/feedcircuit-revisited/ui.clj

shashurup avatar Dec 25 '21 12:12 shashurup

Thanks!

I don't believe we have changed filename handling, there was https://github.com/clojure-emacs/orchard/pull/139/files but we explicitly made sure to not change sematics.

but for the xref window the default directory is .../src/feedcircuit-revisited

This calls my attention. Who is responsible for setting this? Could a better value be an absolute dirname ending in src?

vemv avatar Dec 25 '21 12:12 vemv

As far as I understand this is handled by emacs builtin xref functionality.

shashurup avatar Dec 25 '21 12:12 shashurup

ooops, sorry .... stands for the project root, so the real value is /home/georgy/devel/feedcircuit-revisited/src/feedcircuit-revisited

shashurup avatar Dec 25 '21 12:12 shashurup

Thanks. It sounds off to me, src can contain dirs other than feedcircuit-revisited so I have the impression that a better value would be /home/georgy/devel/feedcircuit-revisited/src, which would be nicely completed with feedcircuit-revisited/ui.clj.

There should be hanlding for source dirs other than src/, e.g. test/ and also custom ones.

I'm not really familiar with this section of cider.el, simply leaving these notes in case they help.

vemv avatar Dec 25 '21 12:12 vemv

(defun xref--show-xref-buffer (fetcher alist)
  (cl-assert (functionp fetcher))
  (let* ((xrefs
          (or
           (assoc-default 'fetched-xrefs alist)
           (funcall fetcher)))
         (xref-alist (xref--analyze xrefs))
         (dd default-directory))
    (with-current-buffer (get-buffer-create xref-buffer-name)
      (setq default-directory dd)
      (xref--xref-buffer-mode)
      (xref--show-common-initialize xref-alist fetcher alist)
      (pop-to-buffer (current-buffer))
      (current-buffer))))

It looks like the directory of xref buffer is inherited from the current buffer, so it seems like the only way is to provide an absolute file name for references.

shashurup avatar Dec 25 '21 13:12 shashurup

I guess should be an easy fix. Admittedly I didn't test the xref backend as much as I wanted to.

bbatsov avatar Dec 25 '21 15:12 bbatsov

I hope so, skimming through the sources I haven't find the notion of "project sources root". I believe it is somewhere in nrepl middleware.

shashurup avatar Dec 25 '21 18:12 shashurup

That's actually a resource URL, but I think that somewhere we have the absolute paths as well.

bbatsov avatar Dec 25 '21 18:12 bbatsov

This issue still seems to be in the latest version. Unfortunately I am unable to resolve it myself.

triplem avatar Apr 30 '23 11:04 triplem

I've implemented a somewhat ugly fix in PR #3349.

jeeger avatar May 31 '23 07:05 jeeger