Skip to content

Commit

Permalink
Use session classloader when loading deferred middleware
Browse files Browse the repository at this point in the history
When loading CIDER middleware via the sideloader we need to make sure that extra
namespaces that are loaded later are also requested via the sideloader. The
original sideloader already provided a macro for
this (with-session-classloader), we just need to use it. This does mean that now
all our middlewares need to depend on the session middleware.
  • Loading branch information
plexus authored and bbatsov committed Sep 1, 2021
1 parent 235ff56 commit f3d3563
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
### Changes

* Parallelize `cider.nrepl.middleware.stacktrace/analyze-stacktrace`.
* [#705](https://github.com/clojure-emacs/cider-nrepl/pull/705): Use the session classloader when loading deferred middleware

## 0.26.0 (2021-04-22)

Expand Down
10 changes: 6 additions & 4 deletions src/cider/nrepl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
[nrepl.middleware.caught :refer [wrap-caught]]
[nrepl.middleware.print :refer [wrap-print wrap-print-optional-arguments]]
[nrepl.middleware.session :refer [session]]
[nrepl.misc :as misc :refer [with-session-classloader]]
[nrepl.server :as nrepl-server]))

;;; Functionality for deferred middleware loading
Expand Down Expand Up @@ -43,12 +44,13 @@
(defn- handler-future
"Check whether a delay exists in the `delayed-handlers`. Otherwise make a delay
out of `fn-name` and place it in the atom. "
[sym ns fn-name]
[sym ns fn-name session]
(or (get @delayed-handlers sym)
(get (swap! delayed-handlers assoc sym
(delay
(locking require-lock
(require ns)
(with-session-classloader session
(require ns))
(resolve-or-fail fn-name))))
sym)))

Expand All @@ -58,7 +60,7 @@
[fn-name handler msg]
(let [ns (symbol (namespace `~fn-name))
sym (symbol (name `~fn-name))]
`(@(handler-future '~sym '~ns '~fn-name)
`(@(handler-future '~sym '~ns '~fn-name (:session ~msg))
~handler ~msg)))

(defmacro ^{:arglists '([name handler-fn descriptor]
Expand All @@ -79,7 +81,7 @@
[descriptor trigger-it]
[trigger-it descriptor])
trigger-it (eval trigger-it)
descriptor (eval descriptor)
descriptor (update (eval descriptor) :requires (fnil conj #{}) #'nrepl.middleware.session/session)
cond (if (or (nil? trigger-it) (set? trigger-it))
(let [ops-set (into (-> descriptor :handles keys set) trigger-it)]
`(~ops-set (:op ~'msg)))
Expand Down

0 comments on commit f3d3563

Please sign in to comment.