This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-05-09
Channels
- # announcements (23)
- # babashka (7)
- # beginners (69)
- # biff (5)
- # calva (12)
- # cider (10)
- # cljfx (9)
- # clojure (60)
- # clojure-austin (1)
- # clojure-europe (14)
- # clojure-korea (2)
- # clojure-losangeles (2)
- # clojure-madison (1)
- # clojure-nl (1)
- # clojure-norway (23)
- # clojure-uk (7)
- # clojuredesign-podcast (16)
- # clojurescript (40)
- # datomic (8)
- # gratitude (4)
- # mount (3)
- # nrepl (2)
- # off-topic (38)
- # pathom (3)
- # releases (1)
- # ring (8)
- # shadow-cljs (7)
I’m using cider + lsp-clojure with the clojure-lsp backend. xref only works if the file containing the target function has already been opened before, otherwise it results in an error like xref--not-found-error: No definitions found for: tx/list-transaction
but if the file containing tx/list-transactions
has been opened before, it works.
I have lsp-enable-xref t
and cider-use-xref nil
I don’t recall exactly why I have cider-use-xref nil
but I think it’s to use cider’s own xref backend instead of emacs.
Also whenever I open a new file see a message in the minibuffer like this LSP :: Connected to [clojure-lsp:42929 /path/to/my/project/.
Any pointers in debugging this are appreciated! I’d like it so that I can jump to definitions in the project without having to open every file first.
If you set cider-use-xref nil
then CIDER won't plug itself into the xref system and only the lsp backend (and possibly other backends) will be present
Note that at least for cider, you cannot change this at runtime - it's most recommended it to set it early in Emacs init
You can M-: xref-backend-functions
to check its runtime value. If you want lsp and nothing else, remove others
I see, I have (lsp--xref-backend t)
and I tried setting cider-use-xref t
before and it did nothing, but as you said, you can’t change this at runtime.
I’ll try setting it early as suggested and report back.
Yeah, it works. Thank you @U45T93RA6! You need to be connected to the REPL for it to work, and I guess one of the advantages of lsp-clojure is the static analysis, but I guess the backend server doesn’t do the necessary indexing for xref to work project-wide without opening each file first? :man-shrugging:
Most certainly neither needs the file to be open for analysis purposes. Both analyse stuff using Clojure (not Elisp). CIDER however had a pretty buggy initial xref implementation, and I recall fixing things such that it doesn't depend on whether there's a buffer open for displaying it. You'd need a reasonably recent CIDER (think: latest 9 months)
Re implementations: lsp is superior as it works with clojurescript. CIDER's works because of a fortunate characteristic of the JVM Clojure compiler that makes a xref implementation easy for us You can learn about that nice hack here https://metaredux.com/posts/2019/05/04/discovering-runtime-function-references-in-clojure.html
Interesting! thanks for sharing, I’ll dive in. > Most certainly neither needs the file to be open for analysis purposes. Then it must be something with my configuration, because I can’t get xref to work properly when combining cider and lsp. It works in other non-clojure projects though. I’m happy with this solution though.