Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make nREPL server persist over resets #121

Merged
merged 2 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion libs/kit-nrepl/deps.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{:paths ["src"]
:deps {org.clojure/tools.logging {:mvn/version "1.2.4"}
integrant/integrant {:mvn/version "0.8.1"}
nrepl/nrepl {:mvn/version "1.0.0"}}}
nrepl/nrepl {:mvn/version "1.0.0"}
io.github.kit-clj/kit-core {:mvn/version "1.0.4"}}}
12 changes: 11 additions & 1 deletion libs/kit-nrepl/src/kit/edge/utils/nrepl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,31 @@
(:require
[clojure.tools.logging :as log]
[integrant.core :as ig]
[kit.ig-utils :as ig-utils]
[nrepl.cmdline]
[nrepl.server :as nrepl]))

(defmethod ig/init-key :nrepl/server
[_ {:keys [port bind ack-port] :as config}]
[_ {:keys [port bind ack-port create-nrepl-port-file?] :as config}]
(try
(let [server (nrepl/start-server :port port
:bind bind
:ack-port ack-port)]
(when create-nrepl-port-file?
(nrepl.cmdline/save-port-file server {}))
(log/info "nREPL server started on port:" port)
(assoc config ::server server))
(catch Exception e
(log/error "failed to start the nREPL server on port:" port)
(throw e))))

(defmethod ig/suspend-key! :nrepl/server [_ _])

(defmethod ig/halt-key! :nrepl/server
[_ {::keys [server]}]
(nrepl/stop-server server)
(log/info "nREPL server stopped"))

(defmethod ig/resume-key :nrepl/server
[key opts old-opts old-impl]
(ig-utils/resume-handler key opts old-opts old-impl))