Update nrepl to handle describe and eldoc (#51)
* Update nrepl to handle describe and eldoc See https://github.com/babashka/sci.nrepl/issues/2 * Update changelog
This commit is contained in:
parent
f24fbbbd79
commit
95740162d4
|
@ -6,6 +6,7 @@
|
|||
|
||||
- Use `window.location.hostname` for WebSocket connection
|
||||
- Upgrade sci configs to `bf8d209e`
|
||||
- Update nrepl implementation, implement `eldoc` (`info`, `lookuup`)
|
||||
|
||||
## v0.5.14 (2023-01-05)
|
||||
|
||||
|
|
|
@ -2,14 +2,17 @@
|
|||
(:require
|
||||
[clojure.edn :as edn]
|
||||
[sci.nrepl.completions :refer [completions]]
|
||||
[sci.nrepl.info :refer [info]]
|
||||
[scittle.core :refer [!last-ns eval-string !sci-ctx]]))
|
||||
|
||||
(defn nrepl-websocket []
|
||||
(.-ws_nrepl js/window))
|
||||
|
||||
(defn nrepl-reply [{:keys [id session]} payload]
|
||||
(defn nrepl-reply [{:keys [id session]} {:keys [ns] :as payload}]
|
||||
(.send (nrepl-websocket)
|
||||
(str (assoc payload :id id :session session :ns (str @!last-ns)))))
|
||||
(str
|
||||
(let [ns (or ns (str @!last-ns))]
|
||||
(assoc payload :id id :session session :ns ns)))))
|
||||
|
||||
(defn handle-nrepl-eval [{:keys [code] :as msg}]
|
||||
(let [[kind val] (try [::success (eval-string code)]
|
||||
|
@ -25,11 +28,46 @@
|
|||
(nrepl-reply msg {:ex (pr-str val)
|
||||
:status ["error" "done"]})))))
|
||||
|
||||
(defn handle-nrepl-info [msg]
|
||||
(let [info (info (assoc msg :ctx @!sci-ctx))]
|
||||
(nrepl-reply msg info)))
|
||||
|
||||
(declare ops)
|
||||
|
||||
(defn
|
||||
handle-describe
|
||||
[msg]
|
||||
(nrepl-reply
|
||||
msg
|
||||
{:versions {"scittle-nrepl" {"major" "0"
|
||||
"minor" "0"
|
||||
"incremental" "1"}}
|
||||
:ops (zipmap
|
||||
(map
|
||||
name
|
||||
(concat
|
||||
(keys ops)
|
||||
;; sci.nrepl browser_server.clj handles:
|
||||
#{:clone :load-file}
|
||||
;; we are lying about close?
|
||||
#{"close"}))
|
||||
(repeat {}))
|
||||
:status ["done"]}))
|
||||
|
||||
(def ops
|
||||
"Operations supported by the nrepl server."
|
||||
{:eval handle-nrepl-eval
|
||||
:info handle-nrepl-info
|
||||
:eldoc handle-nrepl-info
|
||||
:lookup handle-nrepl-info
|
||||
:describe handle-describe
|
||||
:complete (fn [msg] (let [completions (completions (assoc msg :ctx @!sci-ctx))]
|
||||
(nrepl-reply msg completions)))})
|
||||
|
||||
(defn handle-nrepl-message [msg]
|
||||
(case (:op msg)
|
||||
:eval (handle-nrepl-eval msg)
|
||||
:complete (let [completions (completions (assoc msg :ctx @!sci-ctx))]
|
||||
(nrepl-reply msg completions))))
|
||||
(if-let [handler (ops (:op msg))]
|
||||
(handler msg)
|
||||
(nrepl-reply (merge msg {:status ["error" "done"] :err "unkown-op"}) (assoc msg :ctx @!sci-ctx))))
|
||||
|
||||
(defn ws-url [host port path]
|
||||
(str "ws://" host ":" port "/" path))
|
||||
|
|
Loading…
Reference in a new issue