Skip to content

Commit

Permalink
[Fix #447] Fix delayed middleware loading issue (#684)
Browse files Browse the repository at this point in the history
Fixes #553. 
Fixes #657.
  • Loading branch information
Cartmanishere committed Nov 24, 2020
1 parent 15e4aab commit 9d977b4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

## master (unreleased)

### Bugs fixed
### Bugs Fixed

* [#684](https://github.com/clojure-emacs/cider-nrepl/pull/684): Fix delayed middleware loading issue.
* [#683](https://github.com/clojure-emacs/cider-nrepl/pull/683): Support custom `print-method`s in test reports.

## 0.25.4 (2020-10-08)
Expand Down
26 changes: 17 additions & 9 deletions src/cider/nrepl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,27 @@
(or (resolve sym)
(throw (IllegalArgumentException. (format "Cannot resolve %s" sym)))))

(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]
(or (get @delayed-handlers sym)
(get (swap! delayed-handlers assoc sym
(delay
(locking require-lock
(require ns)
(resolve-or-fail fn-name))))
sym)))

(defmacro run-deferred-handler
"Make a delay out of `fn-name` and place it in `delayed-handlers` atom at compile time.
Require and invoke the delay at run-time with arguments `handler` and
`msg`. `fn-name` must be a namespaced symbol (unquoted)."
"Require and invoke the handler delay at run-time with arguments `handler` and `msg`.
`fn-name` must be a namespaced symbol (unquoted)."
[fn-name handler msg]
(let [ns (symbol (namespace `~fn-name))
sym (symbol (name `~fn-name))]
(swap! delayed-handlers assoc sym
(delay
(locking require-lock
(require `~ns)
(resolve-or-fail `~fn-name))))
`(@(get @delayed-handlers '~sym) ~handler ~msg)))
`(@(handler-future '~sym '~ns '~fn-name)
~handler ~msg)))


(defmacro ^{:arglists '([name handler-fn descriptor]
[name handler-fn trigger-it descriptor])}
Expand Down

0 comments on commit 9d977b4

Please sign in to comment.