The Wayback Machine - https://web.archive.org/web/20220410153031/https://github.com/clojure-emacs/cider/issues/3112
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shashurup opened this issue Dec 25, 2021 · 12 comments
Open

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

shashurup opened this issue Dec 25, 2021 · 12 comments
Labels
bug good first issue

Comments

@shashurup
Copy link

@shashurup shashurup commented Dec 25, 2021 •

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

@vemv
Copy link
Member

@vemv vemv commented Dec 25, 2021

Hi! Thanks for the report.

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

@shashurup
Copy link
Author

@shashurup shashurup commented Dec 25, 2021 •

@vemv
Copy link
Member

@vemv vemv commented Dec 25, 2021

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

@shashurup
Copy link
Author

@shashurup shashurup commented Dec 25, 2021

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

@vemv
Copy link
Member

@vemv vemv commented Dec 25, 2021

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?

@shashurup
Copy link
Author

@shashurup shashurup commented Dec 25, 2021

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

@shashurup
Copy link
Author

@shashurup shashurup commented Dec 25, 2021

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

@vemv
Copy link
Member

@vemv vemv commented Dec 25, 2021 •

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.

@shashurup
Copy link
Author

@shashurup shashurup commented Dec 25, 2021 •

(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.

@bbatsov bbatsov added the bug label Dec 25, 2021
@bbatsov
Copy link
Member

@bbatsov bbatsov commented Dec 25, 2021

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

@bbatsov bbatsov added the good first issue label Dec 25, 2021
@shashurup
Copy link
Author

@shashurup shashurup commented Dec 25, 2021

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.

@bbatsov
Copy link
Member

@bbatsov bbatsov commented Dec 25, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue
3 participants