~severeoverfl0w/wedge-mise

670720d43c24495284dcce1db98cdd4269109b6e — Dominic Monroe 1 year, 6 months ago c86e769
Add nREPL support
3 files changed, 52 insertions(+), 1 deletions(-)

M README.adoc
A src/io/dominic/wedge/mise/impl/nrepl.clj
M src/io/dominic/wedge/mise/rebel.clj
M README.adoc => README.adoc +8 -0
@@ 41,6 41,14 @@ OR
# clojure -M:dev -m io.dominic.wedge.mise.rebel
----

You may pass the `--nrepl` flag to the main to start an nREPL server on port 5600 with common middleware loaded.
Use this is your editor asks you to connect to an nREPL server.

[source,shell]
----
# clojure -M -m io.dominic.wedge.mise.rebel --nrepl
----

== SLF4J Warnings

This should only happen if you don't have SLF4J loaded.

A src/io/dominic/wedge/mise/impl/nrepl.clj => src/io/dominic/wedge/mise/impl/nrepl.clj +39 -0
@@ 0,0 1,39 @@
(ns io.dominic.wedge.mise.impl.nrepl
  (:require
    [clojure.tools.deps.alpha.repl :as tda.repl]))

(defn add-libs
  []
  (binding [;; Suppress missing S3Transport warning
            *err* (java.io.StringWriter.)]
    (tda.repl/add-libs
      (cond->
        '{cider/cider-nrepl {:mvn/version "0.25.4"}
          refactor-nrepl/refactor-nrepl {:mvn/version "2.5.0"}
          nrepl/nrepl {:mvn/version "0.8.3"}}
        (try (require 'cljs.analyzer)
             true
             (catch java.io.FileNotFoundException _
               false))
        (assoc 'cider/piggieback {:mvn/version "0.5.2"}))))
  :loaded)

(defn start-nrepl
  ([] (start-nrepl {}))
  ([opts]
   (let [opts (merge {:port 5600
                      :transport (requiring-resolve 'nrepl.transport/bencode)
                      :transport-fn (requiring-resolve 'nrepl.transport/bencode)
                      :handler (apply (requiring-resolve 'nrepl.server/default-handler)
                                      (:middleware opts
                                                   (concat
                                                     @(requiring-resolve 'cider.nrepl.middleware/cider-middleware)
                                                     ['refactor-nrepl.middleware/wrap-refactor]
                                                     (when-let [piggieback (try (requiring-resolve 'cider.piggieback/wrap-cljs-repl)
                                                                                (catch java.io.FileNotFoundException _
                                                                                  false))]
                                                       [piggieback]))))}
                     opts)
         server (apply (requiring-resolve 'nrepl.server/start-server) (apply concat opts))]
     (println ((requiring-resolve 'nrepl.cmdline/server-started-message) server opts))
     ((requiring-resolve 'nrepl.cmdline/save-port-file) server opts))))

M src/io/dominic/wedge/mise/rebel.clj => src/io/dominic/wedge/mise/rebel.clj +5 -1
@@ 1,7 1,8 @@
(ns io.dominic.wedge.mise.rebel
  (:require
    [clojure.tools.deps.alpha.repl :as tda.repl]
    [io.dominic.wedge.mise :as mise]))
    [io.dominic.wedge.mise :as mise]
    [io.dominic.wedge.mise.impl.nrepl :as nrepl]))

(defn- add-libs
  []


@@ 24,6 25,9 @@
    (.setContextClassLoader (Thread/currentThread) (clojure.lang.DynamicClassLoader. cl)))
  (mise/load-libs)
  (mise/setup)
  (when (some #{"--nrepl"} args)
    (nrepl/add-libs)
    (nrepl/start-nrepl))
  (add-libs)
  (load "io/dominic/wedge/mise/rebel/impl")
  ((resolve 'main*)))