meyvn.nrepl_middleware.deps.clj Maven / Gradle / Ivy
The newest version!
(ns meyvn.nrepl-middleware.deps
(:require [nrepl.middleware :refer [set-descriptor!]]
[nrepl.middleware.session :refer [session]]
[nrepl.transport :as t]
[nrepl.misc :refer [response-for]]
[meyvn.nrepl-middleware.dynamic :refer [add-lib]]
[meyvn.nrepl-middleware.state :as state]
[meyvn.nrepl-middleware.proxy :as proxy]
[meyvn.nrepl-middleware.kawa :as kawa]
[meyvn.nrepl-middleware.resources :as resources]
[meyvn.nrepl-middleware.local-root :as local-root]
[meyvn.nrepl-middleware.portal :as portal]
;; [meyvn.nrepl-middleware.flowstorm :as flowstorm]
[meyvn.nrepl-middleware.persistence :refer [persist-lib]])
(:import [java.util.concurrent ScheduledThreadPoolExecutor TimeUnit]))
(defn wrap-deps
[h]
(fn [{:keys [op query session transport] :as msg}]
(condp = op
"meyvn-init" (let [scheduler (ScheduledThreadPoolExecutor. (.availableProcessors (Runtime/getRuntime)))]
(.scheduleAtFixedRate ^ScheduledThreadPoolExecutor scheduler ^Runnable state/update 1 3600 TimeUnit/SECONDS)
(resources/start-watching)
(local-root/start-watching)
(proxy/enable-support)
(t/send transport (response-for msg :status :done :value "OK")))
"meyvn-catalog" (t/send transport (response-for msg :status :done :value (:entries @state/catalog)))
"meyvn-versions" (t/send transport (response-for msg :status :done :value (state/versions query)))
"meyvn-add-dep" (t/send transport (response-for msg
:status :done
:value (if (add-lib query)
"OK"
"No suitable classloader found!")))
"meyvn-persist-dep" (t/send transport (response-for msg :status :done :value (persist-lib query)))
"meyvn-portal" (let [resp (portal/toggle)]
(t/send transport (response-for msg :status :done :value resp)))
;; "meyvn-flowstorm" (let [resp (flowstorm/toggle)]
;; (t/send transport (response-for msg :status :done :value resp)))
"meyvn-kawa" (let [resp (kawa/start-repl)]
(t/send transport (response-for msg :status :done :value resp)))
(h msg))))
(set-descriptor! #'wrap-deps
{:requires #{#'session}
:handles {"meyvn-init" {:doc "Initializes session"}
"meyvn-catalog" {:doc "Returns the catalog of deps compiled from Clojars and Maven"}
"meyvn-add-dep" {:doc "Adds a dependency at runtime"}
"meyvn-persist-dep" {:doc "Persists a dependency in deps.edn"}
"meyvn-versions" {:doc "Searches for an artifact in the catalog. Returns existing versions"}
"meyvn-portal" {:doc "Toggles Portal inspector"}
"meyvn-kawa" {:doc "Starts a Kawa repl"}
;; "meyvn-flowstorm" {:doc "Toggles Flowstorm debugger"}
}})
© 2015 - 2024 Weber Informatics LLC | Privacy Policy