Skip to content

Commit

Permalink
feat: Add interceptors for evaluated results
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Feb 12, 2024
1 parent 94204ea commit 573dac8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/elin/component/interceptor.clj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
elin.interceptor.output/print-output-interceptor
elin.interceptor.nrepl/eval-ns-interceptor
elin.interceptor.nrepl/normalize-path-interceptor
elin.interceptor.nrepl/output-eval-result-to-cmdline-interceptor
elin.interceptor.nrepl/set-eval-result-to-virtual-text-interceptor
elin.interceptor.autocmd/ns-create-interceptor])

(defn- resolve-interceptor [lazy-writer sym]
Expand Down
20 changes: 20 additions & 0 deletions src/elin/interceptor/nrepl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
(:require
[clojure.string :as str]
[elin.constant.interceptor :as e.c.interceptor]
[elin.function.vim.virtual-text :as e.f.v.virtual-text]
[elin.protocol.rpc :as e.p.rpc]
[elin.util.file :as e.u.file]
[elin.util.nrepl :as e.u.nrepl]))

Expand All @@ -25,3 +27,21 @@
(->> response
(e.u.nrepl/update-messages :file e.u.file/normalize-path)
(assoc ctx :response))))})

(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]}]
(when (= "eval" (:op request))
(when-let [v (:value (e.u.nrepl/merge-messages response))]
(e.p.rpc/echo-text writer (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]}]
(when (= "eval" (:op request))
(when-let [v (:value (e.u.nrepl/merge-messages response))]
(e.f.v.virtual-text/set writer (str v))))
ctx)})

0 comments on commit 573dac8

Please sign in to comment.