Give actionable hints when a namespace isn't loaded#3979
Merged
Conversation
152ca85 to
909e8c0
Compare
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.
909e8c0 to
024b82e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.elnow:cider-ns-loaded-p,cider-resolution-failure-messageandcider-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 atC-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-macrocopies that lived incider-macroexpansion.elandcider-macrostep.el, and routescider-find-var,cider-doc, the ClojureDocs commands, the xref ref/dep commands andcider-browse-nsthrough the same helpers.eldev test)eldev lint)