Skip to content

Commit

Permalink
MultiRepl
Browse files Browse the repository at this point in the history
  • Loading branch information
jonpither committed Feb 11, 2016
1 parent 76c0f77 commit 06ecc62
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
2 changes: 2 additions & 0 deletions cider-10.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

Is there a way to detect tooling?

2016-02-10 - Seems fixed

# CIDER-SPY.el doesn't pick up the users alias? (or can't handle situation where there isn't an alias)
3 changes: 3 additions & 0 deletions core/src/cider_spy_nrepl/hub/client_facade.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@
(send! (:hub-client @session) :message {:message message
:from from
:recipient recipient}))

(defn watch-repl [session target]
(send! (:hub-client @session) :watch-repl {:target target}))
10 changes: 10 additions & 0 deletions core/src/cider_spy_nrepl/hub/server_events.clj
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,15 @@
:recipient recipient}))
(log/warn "Message from" from "to unregistered user" recipient)))

(defmethod process :watch-repl [_ session {:keys [target]}]
(if-let [target-session (register/session-from-alias target)]
(do
(log/info "Sending REPL watch request to" (:alias @target-session))
(send-to-nrepl (:channel @target-session)
;; need the return address..
{:op :watch-repl
:watcher (:id @session)}))
(log/warn "Attempt to watch unregistered user" target)))

(defn unregister! [session]
(process nil session {:op :unregister}))
3 changes: 2 additions & 1 deletion core/src/cider_spy_nrepl/middleware/cider_spy_hub.clj
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
(fn [{:keys [op] :as msg}]
(if-let [session (sessions/session! msg)]
(if-let [cider-spy-handler (get cider-spy-hub--nrepl-ops op)]
(cider-spy-handler msg session)
(do (println "aspidjioasjd")
(cider-spy-handler msg session))
(do
(connect-to-hub! session)
(handler msg)))
Expand Down
29 changes: 23 additions & 6 deletions core/src/cider_spy_nrepl/middleware/cider_spy_multi_repl.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
(ns cider-spy-nrepl.middleware.cider-spy-multi-repl
(:require [clojure.tools.nrepl.transport :as nrepl-transport]
[clojure.tools.nrepl.middleware :refer [set-descriptor!]]
[cider-spy-nrepl.middleware.sessions :as sessions]
[cider-spy-nrepl.hub.client-facade :as hub-client]
[cider-spy-nrepl.middleware.cider :as cider]
[clojure.tools.nrepl.middleware.interruptible-eval :refer [interruptible-eval]]))

(deftype TrackingTransport [transport]
Expand All @@ -10,16 +13,30 @@
(recv [this])
(recv [this timeout]))

(defn handle-watch
"This operation is to start watching someone elses REPL"
[{:keys [target] :as msg}]
(let [session (sessions/session! msg)]
(hub-client/watch-repl session target)
(cider/send-connected-msg! session (str "Sent watching REPL request to target " target))))

(defn- track-repl-evals [{:keys [transport] :as msg} handler]
(println "MULTI-REPL" (:code msg))
(handler (assoc msg :transport (TrackingTransport. transport))))

(def cider-spy--nrepl-ops {"cider-spy-hub-watch-repl" #'handle-watch})

(defn wrap-multi-repl
"Multi REPL Middleware - CURRENTLY NEVER GETS CALLED"
[handler]
(println "SETTING")
(fn [{:keys [transport] :as msg}]
(println "MULTI-REPL" (:code msg))
(handler (assoc msg :transport (TrackingTransport. transport)))))
(fn [{:keys [op] :as msg}]
(if-let [cider-spy-handler (get cider-spy--nrepl-ops op)]
(cider-spy-handler msg)
(track-repl-evals msg handler))))

(set-descriptor!
#'wrap-multi-repl
{:expects #{#'interruptible-eval}
:handles {"cider-spy-multi-repl" {:doc "See the cider-spy README"
:returns {} :requires {}}}})
:handles (zipmap (keys cider-spy--nrepl-ops)
(repeat {:doc "See the cider-spy README"
:returns {} :requires {}}))})
1 change: 1 addition & 0 deletions example-project/src/proja/x.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(ns proja.x)

0 comments on commit 06ecc62

Please sign in to comment.