Skip to content

Commit

Permalink
refactor: Rename writer to host
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Feb 16, 2024
1 parent 706939a commit 3aa5a65
Show file tree
Hide file tree
Showing 40 changed files with 360 additions and 363 deletions.
30 changes: 15 additions & 15 deletions .clj-kondo/metosin/malli-types-clj/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
:message :sequential}},
:component/nrepl :any,
:component/interceptor :any,
:component/writer :any}}}}},
:component/host :any}}}}},
handler {:arities {4 {:args [{:op :keys,
:req {:component/nrepl :any,
:component/interceptor :any,
:component/writer :any}}
:component/host :any}}
:map
:map
{:op :keys,
Expand Down Expand Up @@ -80,9 +80,6 @@
get-variable!! {:arities {2 {:args [:any :string], :ret :any}}},
execute!! {:arities {2 {:args [:any :string], :ret :any}}}},
elin.util.id {next-id {:arities {0 {:args [], :ret :int}}}},
elin.test-helper.writer {test-writer {:arities {1 {:args [{:op :keys,
:req {:handler :fn}}],
:ret :any}}}},
elin.component.nrepl.client {connect {:arities {2 {:args [:string :int],
:ret {:op :keys,
:req {:connection {:op :keys,
Expand All @@ -97,6 +94,9 @@
:supported-ops :set,
:initial-namespace :nilable/string,
:version :map}}}}}},
elin.test-helper.host {test-host {:arities {1 {:args [{:op :keys,
:req {:handler :fn}}],
:ret :any}}}},
elin.component.nrepl.connection {bytes->str {:arities {1 {:args [:any],
:ret :any}}},
add-message {:arities {2 {:args [:map :map],
Expand Down Expand Up @@ -149,15 +149,15 @@
:message :sequential}},
:component/nrepl :any,
:component/interceptor :any,
:component/writer :any}}],
:component/host :any}}],
:ret :any}}},
intercept {:arities {1 {:args [{:op :keys,
:req {:message {:op :keys,
:req {:host :string,
:message :sequential}},
:component/nrepl :any,
:component/interceptor :any,
:component/writer :any}}],
:component/host :any}}],
:ret :any}}}},
elin.component.nrepl {client-key {:arities {2 {:args [:string :int],
:ret :string},
Expand Down Expand Up @@ -202,7 +202,7 @@
:message :sequential}},
:component/nrepl :any,
:component/interceptor :any,
:component/writer :any}}
:component/host :any}}
:string
:map],
:ret :any}}},
Expand All @@ -212,47 +212,47 @@
:message :sequential}},
:component/nrepl :any,
:component/interceptor :any,
:component/writer :any}}],
:component/host :any}}],
:ret :any}}},
evaluate-current-top-list {:arities {1 {:args [{:op :keys,
:req {:message {:op :keys,
:req {:host :string,
:message :sequential}},
:component/nrepl :any,
:component/interceptor :any,
:component/writer :any}}],
:component/host :any}}],
:ret :any}}},
evaluate-current-list {:arities {1 {:args [{:op :keys,
:req {:message {:op :keys,
:req {:host :string,
:message :sequential}},
:component/nrepl :any,
:component/interceptor :any,
:component/writer :any}}],
:component/host :any}}],
:ret :any}}},
evaluate-current-expr {:arities {1 {:args [{:op :keys,
:req {:message {:op :keys,
:req {:host :string,
:message :sequential}},
:component/nrepl :any,
:component/interceptor :any,
:component/writer :any}}],
:component/host :any}}],
:ret :any}}},
load-current-file {:arities {1 {:args [{:op :keys,
:req {:message {:op :keys,
:req {:host :string,
:message :sequential}},
:component/nrepl :any,
:component/interceptor :any,
:component/writer :any}}],
:component/host :any}}],
:ret :any}}}},
elin.handler.connect {connect {:arities {1 {:args [{:op :keys,
:req {:message {:op :keys,
:req {:host :string,
:message :sequential}},
:component/nrepl :any,
:component/interceptor :any,
:component/writer :any}}],
:component/host :any}}],
:ret :any}}}},
elin.util.nrepl {merge-messages {:arities {1 {:args [:sequential], :ret :map}}},
update-messages {:arities {3 {:args [:keyword :fn :sequential],
Expand All @@ -275,7 +275,7 @@
:message :sequential}},
:component/nrepl :any,
:component/interceptor :any,
:component/writer :any}}],
:component/host :any}}],
:ret :any}}}},
elin.function.nrepl.cider-nrepl.op {info!! {:arities {3 {:args [:any
:string
Expand Down
10 changes: 5 additions & 5 deletions src/elin/component/clj_kondo.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
(.getAbsolutePath (.getParentFile (io/file path))))

(defn- get-user-dir*
[nrepl lazy-writer]
[nrepl lazy-host]
(e/let [user-dir (e.f.n.system/get-user-dir nrepl)]
(if (empty? user-dir)
(e/-> (e.f.vim/get-current-file-path!! lazy-writer)
(e/-> (e.f.vim/get-current-file-path!! lazy-host)
(get-parent-absolute-path))
user-dir)))
(def get-user-dir
Expand All @@ -47,7 +47,7 @@
(require '[pod.borkdude.clj-kondo :as clj-kondo]))

(defrecord CljKondo
[lazy-writer nrepl analyzing?-atom analyzed-atom]
[lazy-host nrepl analyzing?-atom analyzed-atom]
component/Lifecycle
(start [this]
(assoc this
Expand All @@ -65,7 +65,7 @@
(async/thread
(try
#_{:clj-kondo/ignore [:unresolved-namespace]}
(e/let [user-dir (get-user-dir nrepl lazy-writer)
(e/let [user-dir (get-user-dir nrepl lazy-host)
res (clj-kondo/run! {:lint [user-dir]
:config {:output {:analysis {:protocol-impls true}}}})
cache-path (get-cache-file-path user-dir)]
Expand All @@ -80,7 +80,7 @@
(do (reset! analyzing?-atom true)
(async/thread
(try
(e/let [user-dir (get-user-dir nrepl lazy-writer)
(e/let [user-dir (get-user-dir nrepl lazy-host)
cache-file (get-cache-file-path user-dir)
analyzed (json/parse-stream (io/reader cache-file) keyword)]
(reset! analyzed-atom analyzed))
Expand Down
26 changes: 13 additions & 13 deletions src/elin/component/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@
[elin.util.server :as e.u.server]
[malli.core :as m]))

(m/=> resolve-handler [:=> [:cat e.s.server/?Writer qualified-symbol?]
(m/=> resolve-handler [:=> [:cat e.s.server/?Host qualified-symbol?]
[:or :nil [:cat qualified-keyword? fn?]]])
(defn- resolve-handler [lazy-writer sym]
(defn- resolve-handler [lazy-host sym]
(when-let [f (try
@(requiring-resolve sym)
(catch Exception _
(e.log/warning lazy-writer "Failed to resolve handler:" sym)
(e.log/warning lazy-host "Failed to resolve handler:" sym)
nil))]
[(keyword sym) f]))

(m/=> build-handler-map [:=> [:cat e.s.server/?Writer [:sequential qualified-symbol?]]
(m/=> build-handler-map [:=> [:cat e.s.server/?Host [:sequential qualified-symbol?]]
e.s.handler/?HandlerMap])
(defn- build-handler-map
[lazy-writer handler-symbols]
[lazy-host handler-symbols]
(reduce (fn [accm sym]
(if-let [[k f] (resolve-handler lazy-writer sym)]
(if-let [[k f] (resolve-handler lazy-host sym)]
(assoc accm k f)
accm))
{} handler-symbols))
Expand Down Expand Up @@ -69,28 +69,28 @@
(let [intercept #(apply e.p.interceptor/execute interceptor e.c.interceptor/handler %&)]
(-> (assoc components :message message :config-map config-map)
(intercept
(fn [{:as context :component/keys [writer]}]
(fn [{:as context :component/keys [host]}]
(let [elin (construct-handler-parameter context)
handler-key (get-in elin [:message :method])
resp (if-let [handler-fn (get handler-map handler-key)]
(handler-fn elin)
(let [msg (format "Unknown handler: %s" handler-key)]
(e.log/error writer msg)
(e.log/error host msg)
msg))
resp' (e.u.server/format resp)
resp' (if-let [callback (get-in elin [:message :options :callback])]
(try
(e.p.rpc/notify-function writer "elin#callback#call" [callback resp'])
(e.p.rpc/notify-function host "elin#callback#call" [callback resp'])
;; FIXME
(catch Exception ex
(e.log/error writer "Failed to callback" (ex-message ex))))
(e.log/error host "Failed to callback" (ex-message ex))))
resp')]
(assoc context :response resp'))))
(:response))))

(defrecord Handler
[interceptor ; Interceptor component
lazy-writer ; LazyWriter component
lazy-host ; LazyHost component
nrepl ; Nrepl component
plugin ; Plugin component
includes
Expand All @@ -101,12 +101,12 @@
(start [this]
(let [components {:component/nrepl nrepl
:component/interceptor interceptor
:component/writer lazy-writer}
:component/host lazy-host}
exclude-set (set excludes)
handlers (concat (or includes [])
(or (get-in plugin [:loaded-plugin :handlers]) []))
handlers (remove #(contains? exclude-set %) handlers)
handler-map (build-handler-map lazy-writer handlers)
handler-map (build-handler-map lazy-host handlers)
handler (partial handler components config-map handler-map)]
(assoc this
:handler-map handler-map
Expand Down
Loading

0 comments on commit 3aa5a65

Please sign in to comment.