diff --git a/.clj-kondo/metosin/malli-types-clj/config.edn b/.clj-kondo/metosin/malli-types-clj/config.edn index 3e312058..ca5a7f33 100644 --- a/.clj-kondo/metosin/malli-types-clj/config.edn +++ b/.clj-kondo/metosin/malli-types-clj/config.edn @@ -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, @@ -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, @@ -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], @@ -149,7 +149,7 @@ :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, @@ -157,7 +157,7 @@ :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}, @@ -202,7 +202,7 @@ :message :sequential}}, :component/nrepl :any, :component/interceptor :any, - :component/writer :any}} + :component/host :any}} :string :map], :ret :any}}}, @@ -212,7 +212,7 @@ :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, @@ -220,7 +220,7 @@ :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, @@ -228,7 +228,7 @@ :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, @@ -236,7 +236,7 @@ :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, @@ -244,7 +244,7 @@ :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, @@ -252,7 +252,7 @@ :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], @@ -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 diff --git a/src/elin/component/clj_kondo.clj b/src/elin/component/clj_kondo.clj index 27e9c421..d9344826 100644 --- a/src/elin/component/clj_kondo.clj +++ b/src/elin/component/clj_kondo.clj @@ -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 @@ -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 @@ -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)] @@ -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)) diff --git a/src/elin/component/handler.clj b/src/elin/component/handler.clj index 583245dc..cc3729e7 100644 --- a/src/elin/component/handler.clj +++ b/src/elin/component/handler.clj @@ -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)) @@ -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 @@ -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 diff --git a/src/elin/component/interceptor.clj b/src/elin/component/interceptor.clj index 07b67b91..009832bd 100644 --- a/src/elin/component/interceptor.clj +++ b/src/elin/component/interceptor.clj @@ -16,11 +16,11 @@ (def ^:private config-key :interceptor) -(defn- resolve-interceptor [lazy-writer sym] +(defn- resolve-interceptor [lazy-host sym] (try (deref (requiring-resolve sym)) (catch Exception ex - (e.log/warning lazy-writer "Failed to resolve interceptor" {:symbol sym :ex ex}) + (e.log/warning lazy-host "Failed to resolve interceptor" {:symbol sym :ex ex}) nil))) (defn- valid-interceptor? @@ -28,7 +28,7 @@ (m/validate e.s.interceptor/?Interceptor x)) (defrecord Interceptor - [lazy-writer ; LazyWriter component + [lazy-host ; LazyHost component plugin ; Plugin component includes excludes @@ -40,16 +40,16 @@ (or (get-in plugin [:loaded-plugin :interceptors]) [])) (distinct) (remove #(contains? exclude-set %)) - (keep #(resolve-interceptor lazy-writer %)) + (keep #(resolve-interceptor lazy-host %)) (group-by valid-interceptor?)) interceptor-map (group-by :kind (get grouped-interceptors true))] (when-let [invalid-interceptors (seq (get grouped-interceptors false))] (e.log/debug "Invalid interceptors:" invalid-interceptors) - (e.log/warning lazy-writer "Invalid interceptors:" invalid-interceptors)) - (e.log/debug lazy-writer "Interceptor component: Started") + (e.log/warning lazy-host "Invalid interceptors:" invalid-interceptors)) + (e.log/debug lazy-host "Interceptor component: Started") (assoc this :interceptor-map interceptor-map))) (stop [this] - (e.log/debug lazy-writer "Interceptor component: Stopped") + (e.log/debug lazy-host "Interceptor component: Stopped") (dissoc this :interceptor-map)) e.p.interceptor/IInterceptor @@ -67,7 +67,7 @@ (try (interceptor/execute context' (concat interceptors [terminator'])) (catch Exception ex - (e.log/error lazy-writer "Failed to intercept:" (ex-message ex)))))) + (e.log/error lazy-host "Failed to intercept:" (ex-message ex)))))) e.p.config/IConfigure (configure [this config] @@ -76,7 +76,7 @@ (map keyword) (set)) grouped (->> (or includes []) - (keep #(resolve-interceptor lazy-writer %)) + (keep #(resolve-interceptor lazy-host %)) (group-by valid-interceptor?)) include-map (group-by :kind (get grouped true)) configured (reduce-kv diff --git a/src/elin/component/lazy_host.clj b/src/elin/component/lazy_host.clj new file mode 100644 index 00000000..4ec0ff3e --- /dev/null +++ b/src/elin/component/lazy_host.clj @@ -0,0 +1,91 @@ +(ns elin.component.lazy-host + (:require + [clojure.core.async :as async] + [com.stuartsierra.component :as component] + [elin.protocol.rpc :as e.p.rpc])) + +(defrecord LazyHost + [host-store host-channel] + component/Lifecycle + (start [this] + (let [ch (async/chan)] + (async/go-loop [] + (if-let [host @host-store] + (let [[type & args] (async/LazyHost {:host-store (atom nil)})) diff --git a/src/elin/component/lazy_writer.clj b/src/elin/component/lazy_writer.clj deleted file mode 100644 index 0c00e886..00000000 --- a/src/elin/component/lazy_writer.clj +++ /dev/null @@ -1,94 +0,0 @@ -(ns elin.component.lazy-writer - (:require - [clojure.core.async :as async] - [com.stuartsierra.component :as component] - [elin.log :as e.log] - [elin.protocol.rpc :as e.p.rpc])) - -(defrecord LazyWriter - [writer-store writer-channel] - component/Lifecycle - (start [this] - (e.log/debug "Writer component: Started") - (let [ch (async/chan)] - (async/go-loop [] - (if-let [writer @writer-store] - (let [[type & args] (async/LazyWriter {:writer-store (atom nil)})) diff --git a/src/elin/component/nrepl.clj b/src/elin/component/nrepl.clj index 5c329c42..a77cf12a 100644 --- a/src/elin/component/nrepl.clj +++ b/src/elin/component/nrepl.clj @@ -23,7 +23,7 @@ (defrecord Nrepl [interceptor - lazy-writer + lazy-host clients-store ; atom of [:map-of string? e.c.n.client/?Client] current-client-key-store] ; atom of [:maybe string?]] @@ -107,7 +107,7 @@ (if-let [client (e.p.nrepl/current-client this)] (async/go (let [intercept #(apply e.p.interceptor/execute interceptor e.c.interceptor/nrepl %&)] - (-> {:request msg :writer lazy-writer} + (-> {:request msg :host lazy-host} (intercept (fn [{:as ctx :keys [request]}] (assoc ctx :response (async/ load-plugin [:=> [:cat e.s.server/?Writer string?] [:maybe e.s.plugin/?Plugin]]) +(m/=> load-plugin [:=> [:cat e.s.server/?Host string?] [:maybe e.s.plugin/?Plugin]]) (defn- load-plugin - [lazy-writer edn-file] + [lazy-host edn-file] (let [content (edn/read-string (slurp edn-file)) err (validation-error content)] (if err - (e.log/error lazy-writer "Invalid plugin.edn: " (pr-str err)) + (e.log/error lazy-host "Invalid plugin.edn: " (pr-str err)) content))) -(m/=> load-plugins [:=> [:cat e.s.server/?Writer [:sequential string?]] e.s.plugin/?Plugin]) +(m/=> load-plugins [:=> [:cat e.s.server/?Host [:sequential string?]] e.s.plugin/?Plugin]) (defn- load-plugins - [lazy-writer edn-files] + [lazy-host edn-files] (loop [[edn-file & rest-edn-files] edn-files loaded-files #{} result {:name (str ::plugin) @@ -49,7 +49,7 @@ (recur rest-edn-files loaded-files result) :else - (let [{:as content :keys [handlers interceptors]} (load-plugin lazy-writer edn-file) + (let [{:as content :keys [handlers interceptors]} (load-plugin lazy-host edn-file) loaded-files' (cond-> loaded-files content (conj edn-file)) @@ -61,11 +61,11 @@ (recur rest-edn-files loaded-files' result'))))) (defrecord Plugin - [lazy-writer edn-files loaded-plugin] + [lazy-host edn-files loaded-plugin] component/Lifecycle (start [this] (add-classpaths! edn-files) - (assoc this :loaded-plugin (load-plugins lazy-writer (or edn-files [])))) + (assoc this :loaded-plugin (load-plugins lazy-host (or edn-files [])))) (stop [this] (dissoc this :loaded-plugin))) diff --git a/src/elin/component/server.clj b/src/elin/component/server.clj index 9ec6a68d..b020a5be 100644 --- a/src/elin/component/server.clj +++ b/src/elin/component/server.clj @@ -12,8 +12,8 @@ java.net.ServerSocket)) (defn on-accept - [handler lazy-writer {:keys [message host]}] - (e.p.rpc/set-writer! lazy-writer host) + [handler lazy-host {:keys [message host]}] + (e.p.rpc/set-host! lazy-host host) (if (e.p.rpc/response? message) ;; Receive response @@ -40,7 +40,7 @@ (defrecord Server [host port server-socket server stop-signal - handler lazy-writer] + handler lazy-host] component/Lifecycle (start [this] (when-not server @@ -50,7 +50,7 @@ handler' (:handler handler) server-arg {:host host :server-socket server-socket - :on-accept (partial on-accept handler' lazy-writer) + :on-accept (partial on-accept handler' lazy-host) :stop-signal stop-signal} server (future (if (= e.c.host/nvim host) diff --git a/src/elin/component/server/http.clj b/src/elin/component/server/http.clj index 47529191..87834069 100644 --- a/src/elin/component/server/http.clj +++ b/src/elin/component/server/http.clj @@ -52,12 +52,12 @@ m)) (defrecord HttpServer - [lazy-writer handler host port stop-server] + [lazy-host handler host port stop-server] component/Lifecycle (start [this] (let [port' (get-empty-port)] (async/go - (e.f.vim/set-variable! lazy-writer + (e.f.vim/set-variable! lazy-host e.c.server/http-server-port-variable port')) (assoc this diff --git a/src/elin/function/vim.clj b/src/elin/function/vim.clj index ca20062c..acefba77 100644 --- a/src/elin/function/vim.clj +++ b/src/elin/function/vim.clj @@ -10,13 +10,13 @@ [malli.core :as m])) (m/=> call [:=> - [:cat e.s.server/?Writer string? [:sequential any?]] + [:cat e.s.server/?Host string? [:sequential any?]] e.schema/?ManyToManyChannel]) (defn call - [writer fn-name params] + [host fn-name params] (async/go (let [{:keys [result error]} (->> (e.u.server/format params) - (e.p.rpc/call-function writer fn-name) + (e.p.rpc/call-function host fn-name) (async/ notify [:=> [:cat e.s.server/?Writer string? [:sequential any?]] :nil]) +(m/=> notify [:=> [:cat e.s.server/?Host string? [:sequential any?]] :nil]) (defn notify - [writer fn-name params] + [host fn-name params] (->> (map e.u.server/format params) - (e.p.rpc/notify-function writer fn-name)) + (e.p.rpc/notify-function host fn-name)) nil) -(m/=> luaeval [:=> [:cat e.s.server/?Writer string? [:sequential any?]] +(m/=> luaeval [:=> [:cat e.s.server/?Host string? [:sequential any?]] e.schema/?ManyToManyChannel]) -(defn luaeval [writer code args] - (call writer "luaeval" [code args])) +(defn luaeval [host code args] + (call host "luaeval" [code args])) -(m/=> call!! [:=> [:cat e.s.server/?Writer string? [:sequential any?]] any?]) -(defn call!! [writer function-name params] - (async/ call!! [:=> [:cat e.s.server/?Host string? [:sequential any?]] any?]) +(defn call!! [host function-name params] + (async/ get-current-working-directory!! [:=> [:cat e.s.server/?Writer [:* any?]] (e.schema/error-or string?)]) +(m/=> get-current-working-directory!! [:=> [:cat e.s.server/?Host [:* any?]] (e.schema/error-or string?)]) (defn get-current-working-directory!! - [writer & extra-params] + [host & extra-params] (let [params (or extra-params [])] - (async/ get-current-file-path!! [:=> [:cat e.s.server/?Writer] (e.schema/error-or string?)]) +(m/=> get-current-file-path!! [:=> [:cat e.s.server/?Host] (e.schema/error-or string?)]) (defn get-current-file-path!! - [writer] - (async/ get-cursor-position!! [:=> [:cat e.s.server/?Writer [:* any?]] (e.schema/error-or e.s.vim/?Position)]) +(m/=> get-cursor-position!! [:=> [:cat e.s.server/?Host [:* any?]] (e.schema/error-or e.s.vim/?Position)]) (defn get-cursor-position!! - [writer & extra-params] + [host & extra-params] (e/let [params (or extra-params []) - [bufnum lnum col off curswant] (async/ get-full-path!! [:=> [:cat e.s.server/?Writer] (e.schema/error-or string?)]) +(m/=> get-full-path!! [:=> [:cat e.s.server/?Host] (e.schema/error-or string?)]) (defn get-full-path!! - [writer] - (async/ jump!! [:=> [:cat e.s.server/?Writer string? int? int? [:* any?]] [:maybe e.schema/?Error]]) +(m/=> jump!! [:=> [:cat e.s.server/?Host string? int? int? [:* any?]] [:maybe e.schema/?Error]]) (defn jump!! - [writer path lnum col & [jump-command]] + [host path lnum col & [jump-command]] (let [jump-command (or jump-command "edit") - res (async/ eval!! [:=> [:cat e.s.server/?Writer string?] any?]) +(m/=> eval!! [:=> [:cat e.s.server/?Host string?] any?]) (defn eval!! - [writer s] - (async/ execute! [:=> [:cat e.s.server/?Writer string?] e.schema/?ManyToManyChannel]) +(m/=> execute! [:=> [:cat e.s.server/?Host string?] e.schema/?ManyToManyChannel]) (defn execute! - [writer cmd] - (call writer "elin#internal#execute" [cmd])) + [host cmd] + (call host "elin#internal#execute" [cmd])) -(m/=> execute!! [:=> [:cat e.s.server/?Writer string?] any?]) +(m/=> execute!! [:=> [:cat e.s.server/?Host string?] any?]) (defn execute!! - [writer cmd] - (async/ get-variable!! [:=> [:cat e.s.server/?Writer string?] any?]) +(m/=> get-variable!! [:=> [:cat e.s.server/?Host string?] any?]) (defn get-variable!! - [writer var-name] - (eval!! writer (format "exists('%s') ? %s : v:null" var-name var-name))) + [host var-name] + (eval!! host (format "exists('%s') ? %s : v:null" var-name var-name))) -(m/=> set-variable! [:=> [:cat e.s.server/?Writer string? any?] e.schema/?ManyToManyChannel]) +(m/=> set-variable! [:=> [:cat e.s.server/?Host string? any?] e.schema/?ManyToManyChannel]) (defn set-variable! - [writer var-name value] + [host var-name value] (let [value' (cond (string? value) (str "'" value "'") (true? value) "v:true" (false? value) "v:false" :else value)] - (execute! writer (format "let %s = %s" var-name value')))) + (execute! host (format "let %s = %s" var-name value')))) -(m/=> set-variable!! [:=> [:cat e.s.server/?Writer string? any?] :nil]) +(m/=> set-variable!! [:=> [:cat e.s.server/?Host string? any?] :nil]) (defn set-variable!! - [writer var-name value] - (async/ get-top-list!! [:=> [:cat e.s.server/?Writer int? int?] (e.schema/error-or ?CodeAndPosition)]) +(m/=> get-top-list!! [:=> [:cat e.s.server/?Host int? int?] (e.schema/error-or ?CodeAndPosition)]) (defn get-top-list!! - [writer lnum col] - (-> (e.f.vim/call writer "elin#internal#sexp#get_top_list" [lnum col]) + [host lnum col] + (-> (e.f.vim/call host "elin#internal#sexp#get_top_list" [lnum col]) (async/ get-list!! [:=> [:cat e.s.server/?Writer int? int?] (e.schema/error-or ?CodeAndPosition)]) +(m/=> get-list!! [:=> [:cat e.s.server/?Host int? int?] (e.schema/error-or ?CodeAndPosition)]) (defn get-list!! - [writer lnum col] - (-> (e.f.vim/call writer "elin#internal#sexp#get_list" [lnum col]) + [host lnum col] + (-> (e.f.vim/call host "elin#internal#sexp#get_list" [lnum col]) (async/ get-expr!! [:=> [:cat e.s.server/?Writer int? int?] (e.schema/error-or ?CodeAndPosition)]) +(m/=> get-expr!! [:=> [:cat e.s.server/?Host int? int?] (e.schema/error-or ?CodeAndPosition)]) (defn get-expr!! - [writer lnum col] - (-> (e.f.vim/call writer "elin#internal#sexp#get_expr" [lnum col]) + [host lnum col] + (-> (e.f.vim/call host "elin#internal#sexp#get_expr" [lnum col]) (async/ get-namespace!! [:=> [:cat e.s.server/?Writer] (e.schema/error-or [:maybe string?])]) +(m/=> get-namespace!! [:=> [:cat e.s.server/?Host] (e.schema/error-or [:maybe string?])]) (defn get-namespace!! - [writer] + [host] (try - (e/let [ns-form (async/ ns-form diff --git a/src/elin/function/vim/virtual_text.clj b/src/elin/function/vim/virtual_text.clj index b1034347..520dc80f 100644 --- a/src/elin/function/vim/virtual_text.clj +++ b/src/elin/function/vim/virtual_text.clj @@ -4,12 +4,12 @@ [elin.function.vim :as e.f.vim])) (defn set - ([writer text] - (set writer text {})) - ([writer text options] + ([host text] + (set host text {})) + ([host text options] (let [text (str "=> " text)] - (e.f.vim/notify writer "elin#internal#virtual_text#set" [text options])))) + (e.f.vim/notify host "elin#internal#virtual_text#set" [text options])))) (defn clear-all - [writer] - (e.f.vim/notify writer "elin#internal#virtual_text#clear" [])) + [host] + (e.f.vim/notify host "elin#internal#virtual_text#clear" [])) diff --git a/src/elin/handler/complete.clj b/src/elin/handler/complete.clj index 4dedb6d4..b21a3904 100644 --- a/src/elin/handler/complete.clj +++ b/src/elin/handler/complete.clj @@ -45,14 +45,14 @@ (sort-by :word))) (defn- cider-nrepl-complete - [{:component/keys [nrepl writer]} prefix] - (e/let [ns-str (e.f.v.sexp/get-namespace!! writer) + [{:component/keys [nrepl hsot]} prefix] + (e/let [ns-str (e.f.v.sexp/get-namespace!! hsot) candidates (e.f.n.c.op/complete!! nrepl ns-str prefix)] (format-candidates candidates))) (defn- nrepl-completions - [{:component/keys [nrepl writer]} prefix] - (e/let [ns-str (e.f.v.sexp/get-namespace!! writer) + [{:component/keys [nrepl hsot]} prefix] + (e/let [ns-str (e.f.v.sexp/get-namespace!! hsot) candidates (e.f.n.op/completions!! nrepl ns-str prefix)] (format-candidates candidates))) diff --git a/src/elin/handler/connect.clj b/src/elin/handler/connect.clj index cea2aac0..84bc1231 100644 --- a/src/elin/handler/connect.clj +++ b/src/elin/handler/connect.clj @@ -14,24 +14,24 @@ [:catn [:port int?]] [:catn - [:host string?] + [:hostname string?] [:port int?]]]) (m/=> connect [:=> [:cat e.s.handler/?Elin] any?]) (defn connect - [{:as elin :component/keys [nrepl interceptor writer] :keys [message]}] - (let [[{:keys [host port]} error] (e.u.param/parse ?Params (:params message))] + [{:as elin :component/keys [nrepl interceptor host] :keys [message]}] + (let [[{:keys [hostname port]} error] (e.u.param/parse ?Params (:params message))] (if error - (e.log/error writer "Invalid parameter" error) + (e.log/error host "Invalid parameter" error) (let [intercept #(apply e.p.interceptor/execute interceptor e.c.interceptor/connect %&) - result (-> {:elin elin :host host :port port} + result (-> {:elin elin :hostname hostname :port port} (intercept - (fn [{:as ctx :keys [host port]}] - (if (and host port) - (let [client (e.p.nrepl/add-client! nrepl host port)] + (fn [{:as ctx :keys [hostname port]}] + (if (and hostname port) + (let [client (e.p.nrepl/add-client! nrepl hostname port)] (e.p.nrepl/switch-client! nrepl client) (assoc ctx :client client)) ctx))))] (if (contains? result :client) - (e.log/info writer (format "Connected to %s:%s" (:host result) (:port result))) - (e.log/warning writer "Host or port is not specified." (pr-str (select-keys result [:host :port])))))))) + (e.log/info host (format "Connected to %s:%s" (:hostname result) (:port result))) + (e.log/warning host "Host or port is not specified." (pr-str (select-keys result [:hostname :port])))))))) diff --git a/src/elin/handler/evaluate.clj b/src/elin/handler/evaluate.clj index c2dc8c1a..cdeb9bb8 100644 --- a/src/elin/handler/evaluate.clj +++ b/src/elin/handler/evaluate.clj @@ -32,11 +32,11 @@ (m/=> evaluate-current-top-list [:=> [:cat e.s.handler/?Elin] any?]) (defn evaluate-current-top-list - [{:as elin :component/keys [writer]}] - (e/let [{:keys [lnum col]} (e.f.vim/get-cursor-position!! writer) - ns-str (e.f.v.sexp/get-namespace!! writer) - path (e.f.vim/get-full-path!! writer) - {:keys [code lnum col]} (e.f.v.sexp/get-top-list!! writer lnum col)] + [{:as elin :component/keys [host]}] + (e/let [{:keys [lnum col]} (e.f.vim/get-cursor-position!! host) + ns-str (e.f.v.sexp/get-namespace!! host) + path (e.f.vim/get-full-path!! host) + {:keys [code lnum col]} (e.f.v.sexp/get-top-list!! host lnum col)] (evaluation* elin code {:line lnum :column col :ns ns-str @@ -44,11 +44,11 @@ (m/=> evaluate-current-list [:=> [:cat e.s.handler/?Elin] any?]) (defn evaluate-current-list - [{:as elin :component/keys [writer]}] - (e/let [{:keys [lnum col]} (e.f.vim/get-cursor-position!! writer) - ns-str (e.f.v.sexp/get-namespace!! writer) - path (e.f.vim/get-full-path!! writer) - {:keys [code lnum col]} (e.f.v.sexp/get-list!! writer lnum col)] + [{:as elin :component/keys [host]}] + (e/let [{:keys [lnum col]} (e.f.vim/get-cursor-position!! host) + ns-str (e.f.v.sexp/get-namespace!! host) + path (e.f.vim/get-full-path!! host) + {:keys [code lnum col]} (e.f.v.sexp/get-list!! host lnum col)] (evaluation* elin code {:line lnum :column col :ns ns-str @@ -56,11 +56,11 @@ (m/=> evaluate-current-expr [:=> [:cat e.s.handler/?Elin] any?]) (defn evaluate-current-expr - [{:as elin :component/keys [writer]}] - (e/let [{:keys [lnum col]} (e.f.vim/get-cursor-position!! writer) - ns-str (e.f.v.sexp/get-namespace!! writer) - path (e.f.vim/get-full-path!! writer) - {:keys [code lnum col]} (e.f.v.sexp/get-expr!! writer lnum col)] + [{:as elin :component/keys [host]}] + (e/let [{:keys [lnum col]} (e.f.vim/get-cursor-position!! host) + ns-str (e.f.v.sexp/get-namespace!! host) + path (e.f.vim/get-full-path!! host) + {:keys [code lnum col]} (e.f.v.sexp/get-expr!! host lnum col)] (evaluation* elin code {:line lnum :column col :ns ns-str @@ -68,7 +68,7 @@ (m/=> load-current-file [:=> [:cat e.s.handler/?Elin] any?]) (defn load-current-file - [{:component/keys [nrepl writer]}] - (e/let [path (e.f.vim/get-full-path!! writer)] + [{:component/keys [nrepl host]}] + (e/let [path (e.f.vim/get-full-path!! host)] (e.f.n.op/load-file!! nrepl path) true)) diff --git a/src/elin/handler/internal.clj b/src/elin/handler/internal.clj index c62bb6a1..13de73fa 100644 --- a/src/elin/handler/internal.clj +++ b/src/elin/handler/internal.clj @@ -9,8 +9,8 @@ (m/=> initialize [:=> [:cat e.s.handler/?Elin] any?]) (defn initialize - [{:component/keys [writer]}] - (e.f.vim/notify writer "elin#internal#buffer#info#ready" []) + [{:component/keys [host]}] + (e.f.vim/notify host "elin#internal#buffer#info#ready" []) true) (m/=> intercept [:=> [:cat e.s.handler/?Elin] any?]) @@ -22,6 +22,6 @@ true)) (defn error - [{:component/keys [writer] :keys [message]}] - (e.log/error writer (str "Unexpected error: " (pr-str (:params message)))) + [{:component/keys [host] :keys [message]}] + (e.log/error host (str "Unexpected error: " (pr-str (:params message)))) true) diff --git a/src/elin/handler/lookup.clj b/src/elin/handler/lookup.clj index ee64ef17..5d5d5d3d 100644 --- a/src/elin/handler/lookup.clj +++ b/src/elin/handler/lookup.clj @@ -100,13 +100,13 @@ (generate-cljdoc lookup-resp))) (defn lookup - [{:component/keys [nrepl writer]}] - (e/let [{:keys [lnum col]} (e.f.vim/get-cursor-position!! writer) - ns-str (e.f.v.sexp/get-namespace!! writer) - {:keys [code]} (e.f.v.sexp/get-expr!! writer lnum col) + [{:component/keys [nrepl host]}] + (e/let [{:keys [lnum col]} (e.f.vim/get-cursor-position!! host) + ns-str (e.f.v.sexp/get-namespace!! host) + {:keys [code]} (e.f.v.sexp/get-expr!! host lnum col) resp (e.f.n.c.op/info!! nrepl ns-str code)] (e.f.v.popup/open!! - writer + host (generate-doc resp) {:line "near-cursor" :border [] diff --git a/src/elin/handler/navigate.clj b/src/elin/handler/navigate.clj index add86253..13070798 100644 --- a/src/elin/handler/navigate.clj +++ b/src/elin/handler/navigate.clj @@ -9,11 +9,11 @@ (m/=> jump-to-definition [:=> [:cat e.s.handler/?Elin] any?]) (defn jump-to-definition - [{:component/keys [nrepl writer]}] - (e/let [{:keys [lnum col]} (e.f.vim/get-cursor-position!! writer) - ns (e.f.v.sexp/get-namespace!! writer) - {:keys [code]} (e.f.v.sexp/get-expr!! writer lnum col) + [{:component/keys [nrepl host]}] + (e/let [{:keys [lnum col]} (e.f.vim/get-cursor-position!! host) + ns (e.f.v.sexp/get-namespace!! host) + {:keys [code]} (e.f.v.sexp/get-expr!! host lnum col) {:keys [file line column]} (e.f.n.op/lookup!! nrepl ns code)] (when (and file line) - (e.f.vim/jump!! writer file line (or column 1))) + (e.f.vim/jump!! host file line (or column 1))) true)) diff --git a/src/elin/interceptor/autocmd.clj b/src/elin/interceptor/autocmd.clj index 19d81230..4a17aee6 100644 --- a/src/elin/interceptor/autocmd.clj +++ b/src/elin/interceptor/autocmd.clj @@ -14,11 +14,11 @@ {:name ::ns-create-interceptor :kind e.c.interceptor/autocmd :enter (fn [{:as ctx :keys [elin autocmd-type]}] - (let [{:component/keys [writer nrepl]} elin] + (let [{:component/keys [host nrepl]} elin] (when (and (contains? #{"BufRead" "BufEnter"} autocmd-type) (not (e.p.nrepl/disconnected? nrepl)) - (nil? (e.f.vim/get-variable!! writer ns-created-var-name))) - (e/let [ns-str (e.f.v.sexp/get-namespace!! writer) + (nil? (e.f.vim/get-variable!! host ns-created-var-name))) + (e/let [ns-str (e.f.v.sexp/get-namespace!! host) ns-sym (or (symbol ns-str) (e/incorrect))] (->> `(when-not (clojure.core/find-ns '~ns-sym) @@ -27,5 +27,5 @@ (clojure.core/refer-clojure)) (str) (e.f.n.op/eval!! nrepl)) - (e.f.vim/set-variable!! writer ns-created-var-name true)))) + (e.f.vim/set-variable!! host ns-created-var-name true)))) ctx)}) diff --git a/src/elin/interceptor/connect.clj b/src/elin/interceptor/connect.clj index ebb1925a..08cf793a 100644 --- a/src/elin/interceptor/connect.clj +++ b/src/elin/interceptor/connect.clj @@ -9,18 +9,18 @@ (def port-auto-detecting-interceptor {:name ::port-auto-detecting-interceptor :kind e.c.interceptor/connect - :enter (fn [{:as ctx :keys [elin host port]}] - (if (and host port) + :enter (fn [{:as ctx :keys [elin hostname port]}] + (if (and hostname port) ctx - (let [{:component/keys [writer]} elin + (let [{:component/keys [host]} elin ;; TODO error handling - cwd (e.f.vim/get-current-working-directory!! writer) + cwd (e.f.vim/get-current-working-directory!! host) nrepl-port-file (e.u.file/find-file-in-parent-directories cwd ".nrepl-port") - host' (or host "localhost") + hostname' (or hostname "localhost") port' (some-> nrepl-port-file (slurp) (Long/parseLong))] - (assoc ctx :host host' :port port'))))}) + (assoc ctx :hostname hostname' :port port'))))}) (def output-channel-interceptor {:name ::output-channel-interceptor @@ -28,11 +28,11 @@ :leave (fn [{:as ctx :keys [elin client]}] (when client (async/go-loop [] - (let [{:component/keys [writer interceptor]} elin + (let [{:component/keys [host interceptor]} elin ch (get-in client [:connection :output-channel]) output (async/> {:writer writer :output output} + (->> {:host host :output output} (e.p.interceptor/execute interceptor e.c.interceptor/output)) (recur))))) ctx)}) diff --git a/src/elin/interceptor/nrepl.clj b/src/elin/interceptor/nrepl.clj index e6a142d6..0a789bef 100644 --- a/src/elin/interceptor/nrepl.clj +++ b/src/elin/interceptor/nrepl.clj @@ -31,19 +31,19 @@ (def output-eval-result-to-cmdline-interceptor {:name ::output-eval-result-to-cmdline-interceptor :kind e.c.interceptor/nrepl - :leave (fn [{:as ctx :keys [request writer response]}] + :leave (fn [{:as ctx :keys [request host response]}] (when (= "eval" (:op request)) (when-let [v (:value (e.u.nrepl/merge-messages response))] - (e.p.rpc/echo-text writer (str v)))) + (e.p.rpc/echo-text host (str v)))) ctx)}) (def set-eval-result-to-virtual-text-interceptor {:name ::set-eval-result-to-virtual-text-interceptor :kind e.c.interceptor/nrepl - :leave (fn [{:as ctx :keys [request writer response]}] + :leave (fn [{:as ctx :keys [request host response]}] (when (= "eval" (:op request)) (when-let [v (:value (e.u.nrepl/merge-messages response))] - (e.f.v.virtual-text/set writer + (e.f.v.virtual-text/set host (str v) {:highlight "DiffText"}))) ctx)}) diff --git a/src/elin/interceptor/output.clj b/src/elin/interceptor/output.clj index 25021b41..11759fe5 100644 --- a/src/elin/interceptor/output.clj +++ b/src/elin/interceptor/output.clj @@ -6,6 +6,6 @@ (def print-output-interceptor {:name ::print-output-interceptor :kind e.c.interceptor/output - :enter (fn [{:as ctx :keys [writer output]}] - (e.f.vim/call!! writer "elin#internal#buffer#info#append" [(pr-str output)]) + :enter (fn [{:as ctx :keys [host output]}] + (e.f.vim/call!! host "elin#internal#buffer#info#append" [(pr-str output)]) ctx)}) diff --git a/src/elin/protocol/rpc.clj b/src/elin/protocol/rpc.clj index f0cb4c33..1f20959b 100644 --- a/src/elin/protocol/rpc.clj +++ b/src/elin/protocol/rpc.clj @@ -5,8 +5,8 @@ (response? [this]) (parse-message [this])) -(defprotocol ILazyWriter - (set-writer! [this writer])) +(defprotocol ILazyHost + (set-host! [this host])) (defprotocol IHost (request! [this content]) diff --git a/src/elin/schema/component.clj b/src/elin/schema/component.clj index 903621d1..0b4324c8 100644 --- a/src/elin/schema/component.clj +++ b/src/elin/schema/component.clj @@ -6,19 +6,19 @@ (def ?Atom (e.schema/?instance clojure.lang.Atom)) -(def ?LazyWriter +(def ?LazyHost [:map - [:writer-store (e.schema/?instance clojure.lang.Atom)]]) + [:host-store (e.schema/?instance clojure.lang.Atom)]]) (def ?Interceptor [:map - [:lazy-writer ?LazyWriter] + [:lazy-host ?LazyHost] [:interceptor-map [:map-of keyword? any?]]]) (def ^:private NreplComponent [:map [:interceptor ?Interceptor] - [:lazy-writer ?LazyWriter] + [:lazy-host ?LazyHost] [:clients-store ?Atom] [:current-client-key-store ?Atom]]) diff --git a/src/elin/schema/handler.clj b/src/elin/schema/handler.clj index fef91ccc..e46a9a7c 100644 --- a/src/elin/schema/handler.clj +++ b/src/elin/schema/handler.clj @@ -7,7 +7,7 @@ [:map [:component/nrepl any?] [:component/interceptor any?] - [:component/writer e.s.server/?Writer]]) + [:component/host e.s.server/?Host]]) (def ?Elin (m.util/merge diff --git a/src/elin/schema/interceptor.clj b/src/elin/schema/interceptor.clj index a33e1324..f5bb7d3a 100644 --- a/src/elin/schema/interceptor.clj +++ b/src/elin/schema/interceptor.clj @@ -26,19 +26,19 @@ (def ?OutputContext [:map - [:writer e.s.server/?Writer] + [:host e.s.server/?Host] [:output e.s.nrepl/?Output]]) (def ?ConnectContext [:map [:elin e.s.handler/?Elin] - [:host [:maybe string?]] + [:hostname [:maybe string?]] [:port [:maybe int?]]]) (def ?NreplContext [:map [:request e.s.nrepl/?Message] - [:writer e.s.server/?Writer]]) + [:host e.s.server/?Host]]) (def ?AutocmdContext [:map diff --git a/src/elin/schema/server.clj b/src/elin/schema/server.clj index d0a9688f..cde504e0 100644 --- a/src/elin/schema/server.clj +++ b/src/elin/schema/server.clj @@ -8,8 +8,8 @@ [:host string?] [:message [:sequential any?]]]) -(def ?Writer +(def ?Host [:or [:map [:output-stream (e.schema/?instance java.io.OutputStream)]] - e.s.component/?LazyWriter]) + e.s.component/?LazyHost]) diff --git a/src/elin/system.clj b/src/elin/system.clj index 1b32173e..f0789b49 100644 --- a/src/elin/system.clj +++ b/src/elin/system.clj @@ -4,7 +4,7 @@ [elin.component.clj-kondo :as e.c.clj-kondo] [elin.component.handler :as e.c.handler] [elin.component.interceptor :as e.c.interceptor] - [elin.component.lazy-writer :as e.c.lazy-writer] + [elin.component.lazy-host :as e.c.lazy-host] [elin.component.nrepl :as e.c.nrepl] [elin.component.plugin :as e.c.plugin] [elin.component.server :as e.c.server] @@ -16,31 +16,31 @@ (new-system {:server {:port 0}})) ([config] (component/system-map - :lazy-writer (e.c.lazy-writer/new-lazy-writer config) + :lazy-host (e.c.lazy-host/new-lazy-host config) :plugin (component/using (e.c.plugin/new-plugin config) - [:lazy-writer]) + [:lazy-host]) :interceptor (component/using (e.c.interceptor/new-interceptor config) - [:lazy-writer + [:lazy-host :plugin]) :nrepl (component/using (e.c.nrepl/new-nrepl config) [:interceptor - :lazy-writer]) + :lazy-host]) :clj-kondo (component/using (e.c.clj-kondo/new-clj-kondo config) - [:lazy-writer + [:lazy-host :nrepl]) :handler (component/using (e.c.handler/new-handler config) [:interceptor - :lazy-writer + :lazy-host :nrepl :plugin]) @@ -48,9 +48,9 @@ :http-server (component/using (e.c.s.http/new-http-server config) [:handler - :lazy-writer]) + :lazy-host]) :server (component/using (e.c.server/new-server config) [:handler - :lazy-writer])))) + :lazy-host])))) diff --git a/test/elin/component/handler_test.clj b/test/elin/component/handler_test.clj index c03d6104..b50a2b5a 100644 --- a/test/elin/component/handler_test.clj +++ b/test/elin/component/handler_test.clj @@ -29,8 +29,8 @@ (update ctx :x (partial + 4)))}) (defn- test-handler - [{:component/keys [writer] :keys [message]}] - (e.p.rpc/echo-text writer (str "Hello " (first (:params message)))) + [{:component/keys [host] :keys [message]}] + (e.p.rpc/echo-text host (str "Hello " (first (:params message)))) "OK") (defn test-global-interceptor-handler @@ -61,18 +61,18 @@ (t/deftest new-handler-test (with-redefs [e.c.interceptor/valid-interceptor? (constantly true)] - (let [{:as sys :keys [handler lazy-writer]} (-> (e.system/new-system test-config) - (dissoc :server) - (component/start-system)) + (let [{:as sys :keys [handler lazy-host]} (-> (e.system/new-system test-config) + (dissoc :server) + (component/start-system)) call-test-handler' (partial call-test-handler handler) - writer (h/test-writer {:handler (constantly true)})] + host (h/test-host {:handler (constantly true)})] (try - (e.p.rpc/set-writer! lazy-writer writer) + (e.p.rpc/set-host! lazy-host host) (t/testing "Normal handler" (let [res (call-test-handler' #'test-handler ["world"])] (t/is (= "OK" res)) - (t/is (= ["Hello world"] (h/get-outputs writer))))) + (t/is (= ["Hello world"] (h/get-outputs host))))) (t/testing "Handler using interceptor" (t/testing "Global interceptor" diff --git a/test/elin/component/interceptor_test.clj b/test/elin/component/interceptor_test.clj index 03c6d939..1a92478a 100644 --- a/test/elin/component/interceptor_test.clj +++ b/test/elin/component/interceptor_test.clj @@ -26,7 +26,7 @@ (with-redefs [sut/valid-interceptor? (constantly true)] (let [config {:interceptor {:includes [(symbol #'test-interceptor)]}} {:as sys :keys [interceptor]} (-> (e.system/new-system config) - (select-keys [:lazy-writer :plugin :interceptor]) + (select-keys [:lazy-host :plugin :interceptor]) (component/start-system))] (try (t/is (= 2 diff --git a/test/elin/component/lazy_writer_test.clj b/test/elin/component/lazy_host_test.clj similarity index 50% rename from test/elin/component/lazy_writer_test.clj rename to test/elin/component/lazy_host_test.clj index cfa5b800..376e9e53 100644 --- a/test/elin/component/lazy_writer_test.clj +++ b/test/elin/component/lazy_host_test.clj @@ -1,4 +1,4 @@ -(ns elin.component.lazy-writer-test +(ns elin.component.lazy-host-test (:require [clojure.core.async :as async] [clojure.test :as t] @@ -9,17 +9,17 @@ (t/use-fixtures :once h/malli-instrument-fixture) -(t/deftest new-lazy-writer-test - (let [{:as sys :keys [lazy-writer]} (-> (e.system/new-system) - (select-keys [:lazy-writer]) - (component/start-system)) +(t/deftest new-lazy-host-test + (let [{:as sys :keys [lazy-host]} (-> (e.system/new-system) + (select-keys [:lazy-host]) + (component/start-system)) wrote (atom []) - writer (h/test-writer {:handler #(do (swap! wrote conj %) - "OK")})] + host (h/test-host {:handler #(do (swap! wrote conj %) + "OK")})] (try - (e.p.rpc/notify! lazy-writer ["before"]) - (e.p.rpc/set-writer! lazy-writer writer) - (e.p.rpc/notify! lazy-writer ["after"]) + (e.p.rpc/notify! lazy-host ["before"]) + (e.p.rpc/set-host! lazy-host host) + (e.p.rpc/notify! lazy-host ["after"]) (t/is (= [[2 "after"]] @wrote)) diff --git a/test/elin/component/nrepl_test.clj b/test/elin/component/nrepl_test.clj index 5b52db10..37e38bc7 100644 --- a/test/elin/component/nrepl_test.clj +++ b/test/elin/component/nrepl_test.clj @@ -14,7 +14,7 @@ (t/deftest new-nrepl-test (let [{:as sys :keys [nrepl]} (-> (e.system/new-system) - (select-keys [:interceptor :nrepl :plugin :lazy-writer]) + (select-keys [:interceptor :nrepl :plugin :lazy-host]) (component/start-system))] (try (t/is (nil? (e.p.nrepl/current-client nrepl))) diff --git a/test/elin/component/plugin_test.clj b/test/elin/component/plugin_test.clj index d134adec..d619d0a6 100644 --- a/test/elin/component/plugin_test.clj +++ b/test/elin/component/plugin_test.clj @@ -13,7 +13,7 @@ (let [edn-file (.getAbsolutePath (io/file "example-plugin" "plugin.edn")) config {:plugin {:edn-files [edn-file]}} {:as sys :keys [plugin]} (-> (e.system/new-system config) - (select-keys [:lazy-writer :plugin]) + (select-keys [:lazy-host :plugin]) (component/start-system))] (try (t/is (= {:name (str ::sut/plugin) @@ -25,7 +25,7 @@ (t/deftest new-plugin-no-plugin-test (let [{:as sys :keys [plugin]} (-> (e.system/new-system) - (select-keys [:lazy-writer :plugin]) + (select-keys [:lazy-host :plugin]) (component/start-system))] (try (t/is (= {:name (str ::sut/plugin) diff --git a/test/elin/function/nrepl/system_test.clj b/test/elin/function/nrepl/system_test.clj index d93f62fa..adfb732a 100644 --- a/test/elin/function/nrepl/system_test.clj +++ b/test/elin/function/nrepl/system_test.clj @@ -16,7 +16,7 @@ (t/deftest get-system-info-test (let [{:as sys :keys [nrepl]} (-> (e.system/new-system) - (select-keys [:interceptor :nrepl :plugin :lazy-writer]) + (select-keys [:interceptor :nrepl :plugin :lazy-host]) (component/start-system))] (try (let [client (e.p.nrepl/add-client! nrepl "localhost" h/*nrepl-server-port*)] diff --git a/test/elin/function/vim/sexp_test.clj b/test/elin/function/vim/sexp_test.clj index 877e9127..edc77eeb 100644 --- a/test/elin/function/vim/sexp_test.clj +++ b/test/elin/function/vim/sexp_test.clj @@ -6,24 +6,24 @@ (t/use-fixtures :once h/malli-instrument-fixture) -(defn- get-namespace-writer +(defn- get-namespace-host [ns-form] (let [handler #(if (h/call-function? % "elin#internal#sexp#clojure#get_ns_form") ns-form "")] - (h/test-writer {:handler handler}))) + (h/test-host {:handler handler}))) (t/deftest get-namespace-test (t/testing "no metadata" (t/is (= "foo.bar" - (sut/get-namespace!! (get-namespace-writer "(ns foo.bar)"))))) + (sut/get-namespace!! (get-namespace-host "(ns foo.bar)"))))) (t/testing "with metadata" (t/is (= "foo.bar" - (sut/get-namespace!! (get-namespace-writer "(ns ^:meta foo.bar)")))) + (sut/get-namespace!! (get-namespace-host "(ns ^:meta foo.bar)")))) (t/is (= "foo.bar" - (sut/get-namespace!! (get-namespace-writer "(ns ^{:meta true} foo.bar)"))))) + (sut/get-namespace!! (get-namespace-host "(ns ^{:meta true} foo.bar)"))))) (t/testing "in-ns" (t/is (= "foo.bar" - (sut/get-namespace!! (get-namespace-writer "(in-ns 'foo.bar)")))))) + (sut/get-namespace!! (get-namespace-host "(in-ns 'foo.bar)")))))) diff --git a/test/elin/test_helper.clj b/test/elin/test_helper.clj index 250250bd..e9653c1b 100644 --- a/test/elin/test_helper.clj +++ b/test/elin/test_helper.clj @@ -1,9 +1,9 @@ (ns elin.test-helper (:require [babashka.nrepl.server :as b.n.server] + [elin.test-helper.host :as h.host] [elin.test-helper.message :as h.message] [elin.test-helper.nrepl :as h.nrepl] - [elin.test-helper.writer :as h.writer] [malli.dev.pretty :as m.d.pretty] [malli.instrument :as m.inst])) @@ -31,8 +31,8 @@ (= fn-name (first (nth msg 3))))) (def test-message #'h.message/test-message) -(def get-outputs #'h.writer/get-outputs) -(def test-writer #'h.writer/test-writer) +(def get-outputs #'h.host/get-outputs) +(def test-host #'h.host/test-host) (def test-nrepl-connection #'h.nrepl/test-nrepl-connection) (def test-nrepl-client #'h.nrepl/test-nrepl-client) (def test-nrepl #'h.nrepl/test-nrepl) diff --git a/test/elin/test_helper/writer.clj b/test/elin/test_helper/host.clj similarity index 74% rename from test/elin/test_helper/writer.clj rename to test/elin/test_helper/host.clj index 315b6572..fe0e5bb8 100644 --- a/test/elin/test_helper/writer.clj +++ b/test/elin/test_helper/host.clj @@ -1,4 +1,4 @@ -(ns elin.test-helper.writer +(ns elin.test-helper.host (:require [clojure.core.async :as async] [elin.protocol.rpc :as e.p.rpc] @@ -7,8 +7,8 @@ [elin.util.id :as e.u.id] [malli.core :as m])) -(defrecord TestWriter ; {{{ - [writer-store outputs option] +(defrecord TestHost ; {{{ + [host-store outputs option] e.p.rpc/IHost (request! [_ content] (let [id (e.u.id/next-id) @@ -41,12 +41,12 @@ (echo-message [_ text _highlight] (swap! outputs conj text))) -(defn get-outputs [test-writer] - @(:outputs test-writer)) +(defn get-outputs [test-host] + @(:outputs test-host)) -(m/=> test-writer [:=> [:cat h.message/?TestMessageOption] e.s.server/?Writer]) -(defn test-writer +(m/=> test-host [:=> [:cat h.message/?TestMessageOption] e.s.server/?Host]) +(defn test-host [option] - (map->TestWriter {:writer-store (atom nil) - :outputs (atom []) - :option option})) + (map->TestHost {:host-store (atom nil) + :outputs (atom []) + :option option})) diff --git a/test/elin/test_helper/nrepl.clj b/test/elin/test_helper/nrepl.clj index ad8e6c95..dd805fa4 100644 --- a/test/elin/test_helper/nrepl.clj +++ b/test/elin/test_helper/nrepl.clj @@ -5,7 +5,7 @@ [elin.component.nrepl :as e.c.nrepl] [elin.component.nrepl.client :as e.c.n.client] [elin.protocol.nrepl :as e.p.nrepl] - [elin.test-helper.writer :as h.writer])) + [elin.test-helper.host :as h.host])) (defn- nrepl-connectin-default-handler [msg] @@ -66,16 +66,16 @@ (defn test-nrepl [option] - (let [writer (h.writer/test-writer (merge {:handler identity} - (or (:lazy-writer option) {}))) + (let [host (h.host/test-host (merge {:handler identity} + (or (:lazy-host option) {}))) interceptor (e.c.interceptor/new-interceptor - {:interceptor (merge {:lazy-writer writer + {:interceptor (merge {:lazy-host host :interceptor-map {}} (or (:interceptor option) {}))}) client (test-nrepl-client (or (:client option) {})) nrepl (e.c.nrepl/new-nrepl {:nrepl {:interceptor interceptor - :lazy-writer writer}})] + :lazy-host host}})] (e.p.nrepl/add-client! nrepl client) (e.p.nrepl/switch-client! nrepl client) nrepl)) @@ -83,10 +83,10 @@ (comment (let [ option {} - writer (h.writer/test-writer (merge {:handler identity} - (or (:lazy-writer option) {}))) + host (h.host/test-host (merge {:handler identity} + (or (:lazy-host option) {}))) interceptor (e.c.interceptor/new-interceptor - {:interceptor (merge {:lazy-writer writer + {:interceptor (merge {:lazy-host host :interceptor-map {}} (or (:interceptor option) {}))})]