Open theophilusx opened 3 years ago
After some debugging it looks like clojuredocs-lookup
returns "no-doc" status if the form containing the symbol to look up is not evaluated first by the user in a deps.end based project. In a lein project it appears to work even without user evaluating the form explicitly first.
theophilusx mentioned that this problem isn't present in vanilla emacs, so I assume spacemacs must be doing something to cause the deps.edn project to not be evaluated at start of the session or something like that.
Confirming that Martin's analysis is correct.
Under spacemacs (and BTW it seems Doom Emacs as well), after starting the repl, you need to load (evaluate) the namespace at least once before any of the documentation help lookup functions work correctly. If you don't, cider-clojuredocs will throw the wrong type argument and cider-doc will fail with a message stating the symbol could not be qualitifed (regardless of whether it is a core lib symbol).
Once you have evaluated the buffer at least once, all works fine. This requirement does not exist when running under an emacs configuration which does not use spacemacs and just loads the same packages from ELPA. Under this configuration, there is no need to first evaluate the buffer before trying to do documentation lookup.
Can't imagine how this would work, as CIDER relies on the runtime state to do the lookup, meaning you have to have loaded the things you're trying to resolve/lookup. Might be that in the Lein project some namespaces got required automatically or someting like this.
It has to be something specific to spacemacs (and doom emacs it seems). I don't see this behaviour with Emacs using basic init.el file which just loads the packages from MELPA. Under such a 'vanilla' configuration, once you have started the repl, cider-clojuredocs and cider-doc work fine.
With lein, the core (main) namespace must be loaded automatically as lein leaves the repl in the core namespace. Under CLI, the repl is left in the 'user' namespace.
As this is a spacemacs specific issue, I'm fine for this to be closed.
With lein, the core (main) namespace must be loaded automatically as lein leaves the repl in the core namespace.
Only if :init-ns
is specified. But really - it's not possible for this functionality to work with a namespace that's not loaded. It's just how CIDER and nREPl work.
@theophilusx The way cider works, only special forms are available from the cider help commands until a namespace (any namspace in the project) is evaluated. So until a namespace is evaluated, the docs for if
can be found, but not functions defined in clojure.core as they have not loaded yet.
Configuration in the external tool used to run the REPL might trigger some namespace evaluate, e.g setting :init-ns
specifically for Leiningen, but if that happens its outside of cider and it sounds like its not something to rely upon.
Both docs.cider.mx and https://practicalli.github.io/spacemacs/documentation/cider-doc.html say that a namespace should be evaluated as the first step to using CIDER.
The issue itelf is clear as summarized by @practicalli-john.
It's almost a non-issue and more of a matter of getting used to CIDER's approach.
However, the failure is fairly opaque. Showing a stacktrace is not so good. We should at least handle these nils more gracefully and echo Not found!
or such.
Yeah, that'd be reasonable. Might be even better to let people know that they are looking up stuff in a namespace that hasn't be evaluated (we just have to check that the namespace is missing).
Expected behavior
After starting a repl, moving the cursor over a symbol in the clj file and hitting ', h d' (or SPC m h d) should open a cider docview buffer with the documentation for that symbol (assuming core symbols documented on clojuredocs).
Actual behavior
When entering ', h d' after moving the cursor over a symbol, you are prompted for the symbol to lookup (i.e. cider-try-symbol-at-point fails). You enter the symbol e.g. println and hit enter. You then get the following error
The full backtrace is
Steps to reproduce the problem
Setup a simple CLI based project. I use Sean Corfield's deps.edn from his dot-clojure repository, which includes his clj-new library that allows you to setup a project using lein templates. I used the basic app template to create a test CLI project. The deps.edn is
I also have a .dir-locals.el file which has the following
I open the core.clj file and move the cursor to the 'println' symbol
I then start a repl by entering ', '' (or SPC m , ') and selecting cider-jack-in-clj from the menu. This starts the cider repl. I then ener (with point over the 'println') ', h d' (or SPC m h d) and then am prompted for the symbol to lookup and enter println (this should not be necessary as spacemacs sets cider-prompt-for-symbol to nil, but as that fails, it then prompts to enter the symbol.
Environment & Version information
GNU/Linux (Ubunto 20.04) openjdk-11 spacemacs develop branch (HEAD)
CIDER version information
Lein/Boot version
tools.dep
clojure Version: 1.10.1.561
Emacs version
GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0) of 2020-10-21
Operating system
GNU/Linux Ubuntu 20.04
Additional Info
NREPL messages log