Skip to content

Commit

Permalink
style: Apply standard-clj
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Nov 15, 2024
1 parent 803da32 commit 64f0f5f
Show file tree
Hide file tree
Showing 50 changed files with 405 additions and 417 deletions.
6 changes: 3 additions & 3 deletions src/elin/component/clj_kondo.clj
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
(defn- get-cache-file-path
[user-dir]
(.getAbsolutePath
(io/file (e.u.file/get-cache-directory)
(str (str/replace user-dir "/" "_")
".edn"))))
(io/file (e.u.file/get-cache-directory)
(str (str/replace user-dir "/" "_")
".edn"))))

(m/=> clj-kondo-available? [:=> [:cat string?] boolean?])
(defn- clj-kondo-available?
Expand Down
18 changes: 9 additions & 9 deletions src/elin/component/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@

(defn- handler* [handler-map context]
(-> (e.p.interceptor/execute
(:component/interceptor context) e.c.interceptor/handler context
(fn [{:as context :component/keys [host]}]
(let [handler-key (get-in context [:message :method])
resp (if-let [handler-fn (get handler-map handler-key)]
(handler-fn context)
(let [msg (format "Unknown handler: %s" handler-key)]
(e.message/error host msg)
msg))]
(assoc context :response resp))))
(:component/interceptor context) e.c.interceptor/handler context
(fn [{:as context :component/keys [host]}]
(let [handler-key (get-in context [:message :method])
resp (if-let [handler-fn (get handler-map handler-key)]
(handler-fn context)
(let [msg (format "Unknown handler: %s" handler-key)]
(e.message/error host msg)
msg))]
(assoc context :response resp))))
(:response)
(e.u.server/format)))

Expand Down
12 changes: 6 additions & 6 deletions src/elin/component/interceptor.clj
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
(e.p.interceptor/execute this kind context identity))
(execute [this kind context terminator]
(let [interceptors (concat
(or (get interceptor-map e.c.interceptor/all) [])
(or (get interceptor-map kind) []))
(or (get interceptor-map e.c.interceptor/all) [])
(or (get interceptor-map kind) []))
terminator' {:name ::terminator
:enter terminator}
context' (assoc context
Expand Down Expand Up @@ -150,10 +150,10 @@
interceptors)))
;; NOTE includes should be prioritized over excludes
interceptor-map' (reduce-kv
(fn [accm kind interceptors]
(assoc accm kind (concat (or (get accm kind) [])
interceptors)))
interceptor-map' include-map)]
(fn [accm kind interceptors]
(assoc accm kind (concat (or (get accm kind) [])
interceptors)))
interceptor-map' include-map)]
(assoc this
:config-map config-map'
:interceptor-map interceptor-map'))))
Expand Down
14 changes: 7 additions & 7 deletions src/elin/component/nrepl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@
:component/nrepl this
:request msg}
(intercept
(fn [{:as ctx :keys [request]}]
(assoc ctx :response (e.p.nrepl/notify client request))))
(fn [{:as ctx :keys [request]}]
(assoc ctx :response (e.p.nrepl/notify client request))))
(:response))))
(e/unavailable {:message "Not connected"}))))

Expand All @@ -146,15 +146,15 @@
:component/nrepl this
:request msg}
(intercept
(fn [{:as ctx :keys [request]}]
(assoc ctx :response (async/<! (e.p.nrepl/request client request)))))
(fn [{:as ctx :keys [request]}]
(assoc ctx :response (async/<! (e.p.nrepl/request client request)))))
(:response))))
(async/go
(e/unavailable {:message "Not connected"}))))))

(defn new-nrepl
[config]
(map->Nrepl (merge
(:nrepl config)
{:clients-store (atom {})
:current-client-key-store (atom nil)})))
(:nrepl config)
{:clients-store (atom {})
:current-client-key-store (atom nil)})))
32 changes: 16 additions & 16 deletions src/elin/component/nrepl/client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@

(def ^:private ?ConnectArgumentMap
(m.util/merge
[:map
[:host [:maybe string?]]
[:port [:maybe int?]]]
(-> e.s.nrepl/?Client
(m.util/select-keys [:port-file :language])
(m.util/optional-keys [:port-file :language]))))
[:map
[:host [:maybe string?]]
[:port [:maybe int?]]]
(-> e.s.nrepl/?Client
(m.util/select-keys [:port-file :language])
(m.util/optional-keys [:port-file :language]))))

(m/=> new-client [:function
[:=> [:cat e.s.nrepl/?Connection] e.s.nrepl/?Client]
Expand All @@ -67,19 +67,19 @@
:port nil}))
([conn {:keys [language port-file]}]
(let [clone-resp (e.u.nrepl/merge-messages
(async/<!! (e.p.nrepl/request conn {:op "clone"})))
(async/<!! (e.p.nrepl/request conn {:op "clone"})))
describe-resp (e.u.nrepl/merge-messages
(async/<!! (e.p.nrepl/request conn {:op "describe"})))
(async/<!! (e.p.nrepl/request conn {:op "describe"})))
ns-eval-resp (e.u.nrepl/merge-messages
(async/<!! (e.p.nrepl/request conn {:op "eval" :code (str '(ns-name *ns*))})))]
(async/<!! (e.p.nrepl/request conn {:op "eval" :code (str '(ns-name *ns*))})))]
(map->Client
{:connection conn
:session (:new-session clone-resp)
:supported-ops (set (keys (:ops describe-resp)))
:initial-namespace (:value ns-eval-resp)
:version (:versions describe-resp)
:language language
:port-file port-file}))))
{:connection conn
:session (:new-session clone-resp)
:supported-ops (set (keys (:ops describe-resp)))
:initial-namespace (:value ns-eval-resp)
:version (:versions describe-resp)
:language language
:port-file port-file}))))

(m/=> connect [:=> [:cat ?ConnectArgumentMap] (e.schema/error-or e.s.nrepl/?Client)])
(defn connect
Expand Down
24 changes: 12 additions & 12 deletions src/elin/component/nrepl/connection.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
[malli.core :as m]
[taoensso.timbre :as timbre])
(:import
java.io.PushbackInputStream
java.net.Socket))
(java.io PushbackInputStream)
(java.net Socket)))

(m/=> bytes->str [:=> [:cat any?] e.schema/?NotBytes])
(defn- bytes->str
Expand All @@ -29,9 +29,9 @@

(map? v)
(reduce-kv
(fn [accm k v]
(assoc accm (keyword k) (format-message v)))
{} v)
(fn [accm k v]
(assoc accm (keyword k) (format-message v)))
{} v)

:else
(bytes->str v)))
Expand Down Expand Up @@ -139,12 +139,12 @@
(recur)))

(map->Connection
{:host host
:port port
:socket sock
:read-stream read-stream
:write-stream write-stream
:raw-message-channel raw-message-channel
:response-manager response-manager}))
{:host host
:port port
:socket sock
:read-stream read-stream
:write-stream write-stream
:raw-message-channel raw-message-channel
:response-manager response-manager}))
(catch Exception ex
(e/fault {:message (ex-message ex)} ex))))
12 changes: 6 additions & 6 deletions src/elin/component/plugin.clj
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@
(defn- unify-plugins
[plugins]
(reduce
(fn [accm {:keys [export]}]
(cond-> accm
export
(update :export e.config/merge-configs export)))
{:name (str ::plugin)}
plugins))
(fn [accm {:keys [export]}]
(cond-> accm
export
(update :export e.config/merge-configs export)))
{:name (str ::plugin)}
plugins))

(defrecord Plugin
[;; COMPONENTS
Expand Down
2 changes: 1 addition & 1 deletion src/elin/component/server.clj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
[elin.protocol.lazy-host :as e.p.lazy-host]
[taoensso.timbre :as timbre])
(:import
java.net.ServerSocket))
(java.net ServerSocket)))

(defn on-accept
[handler lazy-host {:keys [message host]}]
Expand Down
6 changes: 3 additions & 3 deletions src/elin/component/server/http.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[elin.protocol.host.rpc :as e.p.h.rpc]
[org.httpkit.server :as h.server])
(:import
java.net.URLDecoder))
(java.net URLDecoder)))

(defn- valid-request?
[{:keys [request-method headers]}]
Expand Down Expand Up @@ -46,8 +46,8 @@
component/Lifecycle
(start [this]
(assoc this :stop-server (h.server/run-server
#(handle this %)
{:port port})))
#(handle this %)
{:port port})))
(stop [this]
(stop-server)
(dissoc this :stop-server))
Expand Down
4 changes: 1 addition & 3 deletions src/elin/component/server/nvim.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
[msgpack.core :as msg]
[taoensso.timbre :as timbre])
(:import
(java.io
DataInputStream
EOFException)))
(java.io DataInputStream EOFException)))

(defrecord NvimMessage
[host message response-manager]
Expand Down
2 changes: 1 addition & 1 deletion src/elin/component/server/vim.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[msgpack.clojure-extensions]
[taoensso.timbre :as timbre])
(:import
java.io.EOFException))
(java.io EOFException)))

(defrecord VimMessage
[host message response-manager]
Expand Down
10 changes: 5 additions & 5 deletions src/elin/component/session_storage.clj
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@

(contains? [this k]
(boolean
(when-let [expires (get-in @memory [k :expires])]
(if (< (now) expires)
true
(do (e.p.storage/delete this k)
false)))))
(when-let [expires (get-in @memory [k :expires])]
(if (< (now) expires)
true
(do (e.p.storage/delete this k)
false)))))

(delete [_ k]
(swap! memory dissoc k)
Expand Down
35 changes: 17 additions & 18 deletions src/elin/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[malli.transform :as mt]
[taoensso.timbre :as timbre])
(:import
java.net.ServerSocket))
(java.net ServerSocket)))

(defmethod aero/reader 'empty-port
[_opts _tag _value]
Expand Down Expand Up @@ -40,7 +40,7 @@

(def ^:private config-transformer
(mt/transformer
mt/default-value-transformer))
mt/default-value-transformer))

(m/=> merge-configs [:function
[:=> [:cat [:maybe map?] [:maybe map?]] map?]
Expand Down Expand Up @@ -72,7 +72,6 @@
([c1 c2 & more-configs]
(reduce merge-configs (or c1 {}) (cons c2 more-configs))))


(defn- configure-handler*
[base-handler-config target-handler-config]
(let [{:keys [includes excludes]} target-handler-config
Expand Down Expand Up @@ -104,29 +103,29 @@
[uses]
(->> (partition 2 uses)
(reduce
(fn [accm [k v]]
(cond-> (update accm :includes conj k)
(seq v)
(update :config-map assoc k v)))
{:includes [] :config-map {}})))
(fn [accm [k v]]
(cond-> (update accm :includes conj k)
(seq v)
(update :config-map assoc k v)))
{:includes [] :config-map {}})))

(defn configure-handler
[base-handler-config target-handler-config]
(configure-handler*
base-handler-config
(if-let [expanded (some-> (:uses target-handler-config)
(expand-uses))]
(configure-handler* expanded (dissoc target-handler-config :uses))
target-handler-config)))
base-handler-config
(if-let [expanded (some-> (:uses target-handler-config)
(expand-uses))]
(configure-handler* expanded (dissoc target-handler-config :uses))
target-handler-config)))

(defn configure-interceptor
[base-interceptor-config target-interceptor-config]
(configure-interceptor*
base-interceptor-config
(if-let [expanded (some-> (:uses target-interceptor-config)
(expand-uses))]
(configure-interceptor* expanded (dissoc target-interceptor-config :uses))
target-interceptor-config)))
base-interceptor-config
(if-let [expanded (some-> (:uses target-interceptor-config)
(expand-uses))]
(configure-interceptor* expanded (dissoc target-interceptor-config :uses))
target-interceptor-config)))

(defn expand-config
[{:as config :keys [handler interceptor]}]
Expand Down
12 changes: 5 additions & 7 deletions src/elin/error.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
(ns elin.error
(:refer-clojure :exclude [let
->
->>]))
(:refer-clojure :exclude [-> ->> let]))

(def ^:private unavailable-type ::unavailable)
(def ^:private interrupted-type ::interrupted)
Expand Down Expand Up @@ -152,7 +150,7 @@

(defn error-or [& vs]
(some
#(when (and %
(not (error? %)))
%)
vs))
#(when (and %
(not (error? %)))
%)
vs))
8 changes: 4 additions & 4 deletions src/elin/function/clj_kondo.clj
Original file line number Diff line number Diff line change
Expand Up @@ -278,21 +278,21 @@

(clojure.pprint/pprint
(filter #(= 'references (:name %)) (var-definitions (elin.dev/$ :clj-kondo))))
;(first (var-definitions (elin.dev/$ :clj-kondo))))
; (first (var-definitions (elin.dev/$ :clj-kondo))))
(clojure.pprint/pprint
(first (namespace-usages (elin.dev/$ :clj-kondo))))

(let [ns-str "elin.handler.lookup"
sym-str "e.p.host/get-cursor-position!!"
sym-str "generate-cljdocc"]
(clojure.pprint/pprint
(lookup clj-kondo ns-str sym-str)))
(clojure.pprint/pprint
(lookup clj-kondo ns-str sym-str)))

(def code-analysis
(e.p.clj-kondo/analyze-code!! (elin.dev/$ :clj-kondo) (str '(defn foo [x]
(let [y (+ x 1)]
y)))))
(clojure.pprint/pprint
(:var-definitions (:analysis code-analysis)))
(:var-definitions (:analysis code-analysis)))
(clojure.pprint/pprint
(:locals (:analysis code-analysis))))
Loading

0 comments on commit 64f0f5f

Please sign in to comment.