Skip to content

Commit

Permalink
feat: Add evaluate-current-top-list handler
Browse files Browse the repository at this point in the history
  • Loading branch information
liquidz committed Jan 18, 2024
1 parent 2a16a26 commit 6398995
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Work in progress
" evaluation
:echo elin#notify('connect', ['localhost', 61081])
:echo elin#callback_test('evaluate', ['(+ 1 2 3)'])
:echo elin#request('evaluate-current-top-list', [])
" request from server
:echo elin#notify('plus', [123, 456])
Expand Down
24 changes: 20 additions & 4 deletions src/elin/handler/core.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
(ns elin.handler.core
(:require
[clojure.core.async :as async]
[elin.function.host :as e.f.host]
[elin.function.sexp :as e.f.sexp]
[elin.interceptor.connect :as e.i.connect]
[elin.log :as e.log]
[elin.nrepl.client.manager :as e.n.c.manager]
[elin.nrepl.message :as e.n.message]
[elin.protocol.nrepl :as e.p.nrepl]
[elin.protocol.rpc :as e.p.rpc]
[elin.util.interceptor :as e.u.interceptor]
Expand Down Expand Up @@ -40,14 +43,27 @@
(e.log/info msg (format "Connected to %s:%s" (:host result) (:port result)))
(e.log/warning msg "Host or port is not specified." (pr-str (select-keys result [:host :port]))))))

(defn- evaluation* [code & [options]]
(-> {:code code :options (or options {})}
(e.u.interceptor/execute
[]
(fn [{:as ctx :keys [code options]}]
(let [resp (async/<!! (e.p.nrepl/eval-op client-manager code options))
resp (e.n.message/merge-messages resp)]
(assoc ctx :response resp))))
(get-in [:response :value])))

(defmethod handler* :evaluate
[{:keys [params]}]
(let [[code] params
resp (async/<!! (e.p.nrepl/eval-op client-manager code {}))]
(e.log/log "FIXME resp" resp)
(pr-str resp)))
(evaluation* (first params)))

(defmethod handler* :plus
[{:as msg :keys [params]}]
(let [res (async/<!! (e.p.rpc/call-function msg "elin#plus_test" params))]
(e.log/info msg "FIXME plus result" (pr-str res))))

(defmethod handler* :evaluate-current-top-list
[msg]
(let [{:keys [lnum col]} (e.f.host/getcurpos msg)
code (e.f.sexp/get-current-top-list msg lnum col)]
(evaluation* code)))

0 comments on commit 6398995

Please sign in to comment.