Skip to content

Give actionable hints when a namespace isn't loaded#3979

Merged
bbatsov merged 4 commits into
masterfrom
unloaded-ns-diagnostics
Jun 20, 2026
Merged

Give actionable hints when a namespace isn't loaded#3979
bbatsov merged 4 commits into
masterfrom
unloaded-ns-diagnostics

Conversation

@bbatsov

@bbatsov bbatsov commented Jun 20, 2026

Copy link
Copy Markdown
Member

A bunch of CIDER commands quietly do nothing (or show a vague "not resolved") when the buffer's namespace hasn't been evaluated into the REPL yet. The macroexpansion commands already grew a hint for this; this PR turns that into a shared mechanism and spreads it around.

The core of it lives in cider-client.el now: cider-ns-loaded-p, cider-resolution-failure-message and cider-ensure-macro. The interesting bit is that a resolution failure now tells two cases apart - the namespace genuinely isn't loaded (so it points you at C-c C-k) versus the symbol just doesn't exist (a typo or a missing require, where loading won't help). The extra round-trip to check that only happens on the failure path, so the common case is untouched.

It also dedups the two byte-for-byte --ensure-macro copies that lived in cider-macroexpansion.el and cider-macrostep.el, and routes cider-find-var, cider-doc, the ClojureDocs commands, the xref ref/dep commands and cider-browse-ns through the same helpers.


  • The commits are consistent with our contribution guidelines
  • You've added tests to cover your change(s)
  • All tests are passing (eldev test)
  • All code passes the linter (eldev lint)
  • You've updated the changelog
  • You've updated the user manual (n/a - no new commands or options, just better messaging)

bbatsov added 4 commits June 20, 2026 13:51
The macroexpansion and macrostep commands each carried a private copy of the
"is this a resolvable macro?" check. Extract that into shared `cider-ensure-macro`
(plus `cider--symbol-operator-p`) in cider-client.el, alongside a reusable
`cider-ns-loaded-p` and a `cider-resolution-failure-message` that tells apart a
namespace that hasn't been loaded (evaluate the buffer) from a symbol that
doesn't resolve - a typo, a missing require, or a definition that's been edited
but not re-evaluated yet.

`cider-ns-loaded-p` consults the track-state namespace cache when cider-nrepl is
present (free) and otherwise falls back to a `find-ns' eval, so the checks also
work against a vanilla nREPL server. Everything here runs only on the failure
path, so the common case is untouched.
Route `cider-find-var`, `cider-doc` and the ClojureDocs lookups through the
shared `cider-resolution-failure-message`, so an unresolved symbol points the
user at loading the buffer when the namespace really isn't loaded, instead of a
bare "Symbol not resolved". Also promote the dwim resource/var error to a
`user-error` for consistency.
`cider-xref-fn-refs`/`cider-xref-fn-deps` reported "no references/dependencies
found" whether the symbol had none or simply couldn't be resolved. Check the
var first and fall back to the shared resolution hint when it doesn't resolve,
and bail out early with a clear message when there's no symbol at point.
`cider-browse-ns` likewise now warns when it's pointed at a namespace that isn't
loaded instead of popping up an empty buffer.
The shared diagnostic helpers have landed and several command families now route
through them; record what's done and what's left.
@bbatsov bbatsov force-pushed the unloaded-ns-diagnostics branch from 909e8c0 to 024b82e Compare June 20, 2026 10:52
@bbatsov bbatsov merged commit 4cb74cf into master Jun 20, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants