Skip to content

Commit

Permalink
Merge pull request #4 from liquidz/dev
Browse files Browse the repository at this point in the history
Use standard clojure style
  • Loading branch information
liquidz authored Nov 15, 2024
2 parents df25763 + 64f0f5f commit 4824985
Show file tree
Hide file tree
Showing 55 changed files with 417 additions and 434 deletions.
12 changes: 0 additions & 12 deletions .cljstyle.edn

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ jobs:
with:
bb: latest
clj-kondo: latest
cljstyle: latest
- uses: actions/cache@v4
with:
path: ~/.m2
Expand Down
4 changes: 4 additions & 0 deletions DEVELOPMENT.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
== Type checking

* Type checking with https://github.com/metosin/malli[malli] is enabled by default.

== Code formatting

* https://github.com/oakmac/standard-clojure-style-js[Standard Clojure Style] is used for code formatting.
7 changes: 5 additions & 2 deletions bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
lint {:doc "Clj-kondo linting"
:task (shell "clj-kondo --lint src:test")}

format-check {:doc "Cljstyle check"
:task (shell "cljstyle check")}
format-check {:doc "Check code formats"
:task (shell "npx @chrisoakman/standard-clojure-style check src test")}

format-fix {:doc "Fix code formats"
:task (shell "npx @chrisoakman/standard-clojure-style fix src test")}

test {:doc "Run unit tests"
:extra-paths ["dev" "test"]
Expand Down
5 changes: 3 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
clojure-msgpack/clojure-msgpack {:mvn/version "1.2.1"},
com.cognitect/transit-clj {:mvn/version "1.0.333"},
com.stuartsierra/component {:mvn/version "1.1.0"},
com.taoensso/timbre {:mvn/version "6.5.0"},
com.taoensso/timbre {:mvn/version "6.6.0"},
exoscale/interceptor {:mvn/version "0.1.17"},
hiccup/hiccup {:mvn/version "2.0.0-RC1"},
http-kit/http-kit {:mvn/version "2.8.0-RC1"},
Expand All @@ -22,7 +22,7 @@
nrepl/bencode {:mvn/version "1.2.0"},
org.babashka/babashka.impl.java {:mvn/version "0.1.10"},
org.babashka/cli {:mvn/version "0.8.59"},
org.babashka/http-client {:mvn/version "0.4.21"},
org.babashka/http-client {:mvn/version "0.4.22"},
org.babashka/sci.impl.types {:mvn/version "0.0.2"},
org.clj-commons/digest {:mvn/version "1.4.100"},
org.clojure/clojure {:mvn/version "1.12.0"},
Expand All @@ -36,6 +36,7 @@
org.clojure/tools.cli {:mvn/version "1.0.214"},
org.clojure/tools.logging {:mvn/version "1.1.0"},
org.flatland/ordered {:mvn/version "1.15.12"},
org.jsoup/jsoup {:mvn/version "1.18.1"},
pogonos/pogonos {:mvn/version "0.2.1"},
rewrite-clj/rewrite-clj {:mvn/version "1.1.48"},
selmer/selmer {:mvn/version "1.12.59"}},
Expand Down
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
Loading

0 comments on commit 4824985

Please sign in to comment.