Skip to content

Commit

Permalink
nrepl: land piggieback overhaul to implement compiler switching
Browse files Browse the repository at this point in the history
  • Loading branch information
darwin committed Sep 28, 2016
1 parent 4e9c39e commit 64f1b66
Show file tree
Hide file tree
Showing 7 changed files with 377 additions and 225 deletions.
20 changes: 10 additions & 10 deletions src/nrepl/dirac/nrepl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@

; -- support for booting into CLJS REPL -------------------------------------------------------------------------------------

(defn after-launch! [runtime-tag repl-env weasel-url]
(log/trace "after-launch handler called with repl-env:\n" (logging/pprint repl-env))
(piggieback/weasel-launched! weasel-url runtime-tag))

(defn bootstrap! [& [config]]
(let [effective-confg (config/get-effective-config config)
weasel-repl-options (:weasel-repl effective-confg)
repl-options (assoc weasel-repl-options :after-launch (partial after-launch! (:runtime-tag effective-confg)))
repl-env (weasel-server/make-weasel-repl-env repl-options)]
(log/trace "starting cljs-repl with repl-env:\n" (logging/pprint repl-env))
(piggieback/start-cljs-repl! repl-env)))
(let [effective-nrepl-confg (config/get-effective-config config)
weasel-repl-options (:weasel-repl effective-nrepl-confg)
runtime-tag (:runtime-tag effective-nrepl-confg)
after-launch! (fn [repl-env weasel-url]
(log/trace "after-launch handler called with repl-env:\n" (logging/pprint repl-env))
(piggieback/weasel-server-started! weasel-url runtime-tag))
repl-options (assoc weasel-repl-options :after-launch after-launch!)
repl-env (weasel-server/make-weasel-repl-env repl-options)
cljs-repl-options (:cljs-repl-options effective-nrepl-confg)]
(piggieback/start-cljs-repl! effective-nrepl-confg repl-env cljs-repl-options)))

(defn boot-dirac-repl! [& [config]]
(let [effective-config (config/get-effective-config config)]
Expand Down
12 changes: 11 additions & 1 deletion src/nrepl/dirac/nrepl/config.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
(ns dirac.nrepl.config
(:require [dirac.lib.utils :refer [assoc-env-val deep-merge-ignoring-nils]]))
(:require [dirac.lib.utils :refer [assoc-env-val deep-merge-ignoring-nils]]
[clojure.tools.nrepl :as nrepl]))

(def ^:dynamic standard-repl-init-code
(nrepl/code
(ns cljs.user
(:require [cljs.repl :refer-macros (source doc find-doc apropos dir pst)]))))

(def default-config
{:log-out :console ; this is important, nREPL middleware captures output and logs be sent to client
Expand All @@ -8,6 +14,9 @@
:weasel-repl {:host "localhost"
:port 8232
:range 10} ; how many ports to try if the default port is taken
:preferred-compiler "dirac/new"
:cljs-repl-options nil
:repl-init-code standard-repl-init-code
:runtime-tag "unidentified"})

; -- environment ------------------------------------------------------------------------------------------------------------
Expand All @@ -17,6 +26,7 @@
(assoc-env-val [:log-level] :dirac-nrepl-log-level)
(assoc-env-val [:log-out] :dirac-nrepl-log-out)
(assoc-env-val [:skip-logging-setup] :dirac-nrepl-skip-logging-setup :bool)
(assoc-env-val [:preferred-compiler] :dirac-nrepl-preferred-compiler)
(assoc-env-val [:weasel-repl :host] :dirac-nrepl-weasel-host)
(assoc-env-val [:weasel-repl :port] :dirac-nrepl-weasel-port :int)
(assoc-env-val [:weasel-repl :range] :dirac-nrepl-weasel-range :int)))
Expand Down
15 changes: 3 additions & 12 deletions src/nrepl/dirac/nrepl/helpers.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns dirac.nrepl.helpers
(:require [dirac.nrepl.version :refer [version]])
(:import (java.util UUID)
(java.io StringWriter PrintWriter)))
(:require [dirac.nrepl.version :refer [version]]
[dirac.logging :as logging])
(:import (java.util UUID)))

(defmacro with-err-output [& body]
`(binding [*out* *err*]
Expand All @@ -16,12 +16,3 @@

(defn generate-uuid []
(str (UUID/randomUUID)))

(defn get-printed-stack-trace []
(try
(throw (Throwable. ""))
(catch Throwable e
(let [string-writer (StringWriter.)
writer (PrintWriter. string-writer)]
(.printStackTrace e writer)
(str string-writer)))))
Loading

0 comments on commit 64f1b66

Please sign in to comment.