Skip to content

Commit

Permalink
change nrepl piggieback binding so its immediately available after set
Browse files Browse the repository at this point in the history
  • Loading branch information
thheller committed Mar 18, 2018
1 parent 9c81abe commit 6fecb5b
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/main/shadow/cljs/devtools/server/nrepl.clj
Expand Up @@ -117,11 +117,25 @@

(defn cljs-select [next]
(fn [{:keys [session op] :as msg}]
(swap! session assoc #'api/*nrepl-active* true)

(let [repl-var #'api/*nrepl-cljs*]
(when-not (contains? @session repl-var)
(swap! session assoc repl-var nil))

(swap! session assoc #'api/*nrepl-active* true)
(swap! session assoc repl-var nil)

;; always set the piggieback compiler env binding to a IDeref
;; so its immediately derefable when the nrepl-cljs binding is set
;; if we only add the binding on message in it isn't available
;; for some cider-nrepl middleware that already uses it on message-out
(swap! session assoc #'cemerick.piggieback/*cljs-compiler-env*
;; FIXME: cider seems to use this in places and bind cljs.env/*compiler* with it
;; if something tries to write to it this will fail?
(reify
clojure.lang.IDeref
(deref [_]
(when-let [build-id @repl-var]
(when-let [worker (api/get-worker build-id)]
(-> worker :state-ref deref :build-state :compiler-env)))))))

(let [build-id
(get @session repl-var)
Expand All @@ -137,10 +151,6 @@
(println)
(flush))

(if worker
(swap! session assoc #'cemerick.piggieback/*cljs-compiler-env* (-> worker :state-ref deref :build-state :compiler-env))
(swap! session dissoc #'cemerick.piggieback/*cljs-compiler-env*))

(-> msg
(cond->
worker
Expand Down

0 comments on commit 6fecb5b

Please sign in to comment.