From 573dac872bd2bff5ad7210236f293a08dedf0cd5 Mon Sep 17 00:00:00 2001 From: liquidz Date: Tue, 13 Feb 2024 00:10:28 +0900 Subject: [PATCH] feat: Add interceptors for evaluated results --- src/elin/component/interceptor.clj | 2 ++ src/elin/interceptor/nrepl.clj | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/elin/component/interceptor.clj b/src/elin/component/interceptor.clj index 3c9a1525..ed620617 100644 --- a/src/elin/component/interceptor.clj +++ b/src/elin/component/interceptor.clj @@ -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] diff --git a/src/elin/interceptor/nrepl.clj b/src/elin/interceptor/nrepl.clj index 512329d5..059ac191 100644 --- a/src/elin/interceptor/nrepl.clj +++ b/src/elin/interceptor/nrepl.clj @@ -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])) @@ -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)})