I have a Luminus project with the server running on localhost:7000
. I use cider-connect
to attach myself to this repl, but I'm met with the following wall:
; CIDER 0.10.0snapshot (package: 20150820.852) \
(Java 1.7.0_51, Clojure 1.7.0, nREPL 0.2.10)
WARNING: The following required nREPL ops are not supported:
apropos classpath complete eldoc format-code format-edn info inspect-pop \
inspect-push inspect-refresh macroexpand ns-list ns-vars ns-path refresh \
resource stacktrace toggle-trace-var toggle-trace-ns undef
Please, install (or update) cider-nrepl 0.10.0-SNAPSHOT and restart CIDER
I would imagine at least one of these is required for debugging; attempts to instrument a function yield
clojure.lang.LispReader$ReaderException: java.lang.RuntimeException: \
No reader function for tag dbg
I can debug just fine with a 'normal' Clojure project. I've tried adding the boilerplate that normally goes in ~/.lein/profiles.clj
to the project's project.clj
to no effect:
:profiles/dev {:dependencies [[org.clojure/tools.nrepl "0.2.10"]]
:plugins [[cider/cider-nrepl "0.10.0-SNAPSHOT"]]}
How can I attach CIDER's debugger to this web application?
In the interest of saving time of people who have similar issue I'll post summary here as an answer.
Thanks to Benedek Fazekas from clojure-emacs/refactor-nrepl
's gitter and Sean Allred.
To attach Cider
to Luminus
application (and probably any other application which uses embedded nrepl server
as an opportunity of connecting to it while it's running) you should do two things:
Provide all desired middleware as :handler
to clojure.tools.nrepl.server/start-server
. To do this you should have libraries which contain middleware listed somewhere where lein
can find them (e.g. in project.clj
:dependencies
).
Run application which launches embedded nrepl server
and connect Cider
to it using cider-connect
.
Beside cider-nrepl
I want to use refactor-nrepl
which is needed by Clojure refactor. With example project from Luminus website first thing can be done like this:
(ns guestbook.core
(:require [guestbook.handler :refer [app init destroy]]
[immutant.web :as immutant]
[guestbook.db.migrations :as migrations]
[clojure.tools.nrepl.server :as nrepl]
[clojure.tools.logging :as log]
[environ.core :refer [env]]
[cider.nrepl :refer [cider-middleware]]
[refactor-nrepl middleware])
(:gen-class))
...
(defn cider&cljr-nrepl-handler []
(apply nrepl/default-handler (cons #'refactor-nrepl.middleware/wrap-refactor
(map resolve cider-middleware))))
(defn start-app
"e.g. lein run 3000"
[[port]]
(let [port (http-port port)]
(.addShutdownHook (Runtime/getRuntime) (Thread. stop-app))
(when-let [repl-port (env :nrepl-port)]
(repl/start {:port (parse-port repl-port)
:handler (cider&cljr-nrepl-handler)}))
(http/start {:handler app
:init init
:port port})))
Then you can run your Luminus
app with lein run
and connect it with Cider
using cider-connect
(M-x cider-connect
or C-c M-c
), by default url to connect is localhost:7000
.
Presumably, embedded nrepl server
in Luminus
is intended to be used when application is already deployed somewhere and you want to do some live debugging.
For local development there is standard way:
lein repl
in the project root. Cider
will do the job with lein repl :headless
on cider-jack-in
(C-c M-j
).repl
in yourapp.core
namespace where you can run (http/start {:port 3000 :init init :handler app})
and enjoy! In this case we don't need embedded nrepl server
. To stop http server run (http/stop destroy)
. It is described here.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With