lsp

JR 2026-01-09T01:25:03.253629Z

Internals question: I'm trying to find the references (invocations) to a function for a test file. As part of this, I'm using this (hardcoded for testing) call (q/find-element-from-sym db 'user 'foo-bar-2) to find foo-bar-2 elements in this file:

(defn foo-bar-2 []
  (println "hi"))
(foo-bar-2)
This works fine in a unit test, but in the editor (Calva), with the same code, q/find-element-from-sym returns nil. There is no namespace in either the test or the editor file. Any idea what might cause this? (more in thread)

ericdallo 2026-01-09T13:14:08.345089Z

we define what is internal vs external according to the source-paths which are defined in the clojure-lsp startup

ericdallo 2026-01-09T13:14:26.270889Z

so it's likely that in calva, the source-paths are not including that file, so clojure-lsp is considering external of the proejct

ericdallo 2026-01-09T13:15:06.109299Z

one quick way to debug that, is call server info (I believe there is a calva command for that) which should show the classpath + source-paths considered by clojure-lsp

JR 2026-01-09T17:49:35.676709Z

Ah, I see. You're right that the file in Calva isn't in the source path. But... what does that mean for q/find-element-from-sym? Does that just not work for external files, despite the data being in the database? If so, do I 1) sort through the database myself (without clojure-lsp.queries) to find the element, 2) use a different clojure-lsp.queries API or 3) assume that the user knows that some refactorings won't work for external files?

JR 2026-01-09T17:53:40.618959Z

Hm... I could try q/find-element-under-cursor.

ericdallo 2026-01-09T18:46:14.121619Z

can you elaborate what kind of problem you are trying to solve for me to understand why you got to q/find-element-from-sym

ericdallo 2026-01-09T18:47:49.131179Z

some functions from clojure-lsp.queries were not supposed to be public, I never managed to create a public API for it, but maybe we should

ericdallo 2026-01-09T18:48:10.768969Z

q/find-element-under-cursor, although its name, it checks only for internal-analysis https://github.com/clojure-lsp/clojure-lsp/blob/70daed87e9858b13e3d878df183b16fda808d735/lib/src/clojure_lsp/queries.clj#L823 especially for performance reasons

ericdallo 2026-01-09T18:48:41.444699Z

q/find-element-under-cursor is more likely to work

JR 2026-01-09T19:01:56.861389Z

Ah yeah, I saw that, which made me suspicious when I saw the external: true part I'm working on an inline-function refactoring. I walked up from the cursor to the function name (after the defn) and then I'm trying to find the definition in the database so I can find all the call points to inline via q/find-references

JR 2026-01-09T19:02:25.447859Z

I'll try q/find-element-under-cursor, I don't know how I didn't see that at first

ericdallo 2026-01-09T19:14:09.861269Z

I see, for internal usage, q/find-elemnt-under-cursor and q/find-definition are the ones

ericdallo 2026-01-09T19:15:26.022519Z

you can see that q/find-element-under-cursor has lots of usages across clojure-lsp

JR 2026-01-09T19:23:17.462869Z

That did the trick! Thanks!

JR 2026-01-09T01:31:25.484689Z

I looked into the database with (get-in db [:analysis uri]) and found the 'foo-bar-2 symbol. The unit tests had:

external? false,
while in the editor, the same code has:
external? true,

JR 2026-01-09T01:31:56.805949Z

Here's the diff from the database: