File: cider-xref-source.el.html
Find references to a Clojure var by scanning the project's source files,
rather than introspecting the runtime. The runtime-based approach (see
cider-xref-fn-refs) only sees namespaces that have been loaded into the
REPL; this one covers the whole project on disk, including code that hasn't
been evaluated yet.
The strategy splits the problem along its natural seam: resolving the symbol
at point to a canonical ns/name genuinely needs semantic knowledge, so we
use the lightweight nREPL info/lookup op (via cider-var-info) for that
one step.
Finding the occurrences is a breadth problem, so we hand it off to a fast text
search (Emacs' own xref-matches-in-files, i.e. grep/ripgrep) and then refine
the candidates per file.
The refinement is what makes this Clojure-aware rather than a dumb grep: each
candidate file's (ns ...) form is parsed to learn that file's alias for the
target namespace and whether it refers the name, so only the forms a given
file actually licenses are matched. Matches inside strings and comments are
dropped via the buffer's syntax table.
This is a heuristic, not a resolved index. It can include shadowing locals
and same-named vars referred from a different namespace, and it can miss
references hidden in .cljc reader-conditional branches or built from strings
at runtime. When precision matters more than coverage, clojure-lsp's static
analysis is the better tool.