Add hoplon and javelin as a plugin (#73)
* Hoplon and Javelin plugins * Only Hoplon plugin * Bump promesa * Update sci context access/update * Bump sci
This commit is contained in:
parent
f63d50215d
commit
d456009ca1
12 changed files with 89 additions and 24 deletions
|
|
@ -4,6 +4,7 @@
|
|||
[goog.object :as gobject]
|
||||
[goog.string]
|
||||
[sci.core :as sci]
|
||||
[sci.ctx-store :as store]
|
||||
[sci.impl.unrestrict]
|
||||
[scittle.impl.common :refer [cljns]]
|
||||
[scittle.impl.error :as error]
|
||||
|
|
@ -45,12 +46,12 @@
|
|||
'sci.core {'stacktrace sci/stacktrace
|
||||
'format-stacktrace sci/format-stacktrace}})
|
||||
|
||||
(def !sci-ctx
|
||||
(atom (sci/init {:namespaces namespaces
|
||||
:classes {'js js/globalThis
|
||||
:allow :all
|
||||
'Math js/Math}
|
||||
:ns-aliases {'clojure.pprint 'cljs.pprint}})))
|
||||
(store/reset-ctx!
|
||||
(sci/init {:namespaces namespaces
|
||||
:classes {'js js/globalThis
|
||||
:allow :all
|
||||
'Math js/Math}
|
||||
:ns-aliases {'clojure.pprint 'cljs.pprint}}))
|
||||
|
||||
(def !last-ns (volatile! @sci/ns))
|
||||
|
||||
|
|
@ -58,21 +59,21 @@
|
|||
(sci/binding [sci/ns @!last-ns]
|
||||
(let [rdr (sci/reader s)]
|
||||
(loop [res nil]
|
||||
(let [form (sci/parse-next @!sci-ctx rdr)]
|
||||
(let [form (sci/parse-next (store/get-ctx) rdr)]
|
||||
(if (= :sci.core/eof form)
|
||||
(do
|
||||
(vreset! !last-ns @sci/ns)
|
||||
res)
|
||||
(recur (sci/eval-form @!sci-ctx form))))))))
|
||||
(recur (sci/eval-form (store/get-ctx) form))))))))
|
||||
|
||||
(defn ^:export eval-string [s]
|
||||
(try (-eval-string s)
|
||||
(catch :default e
|
||||
(error/error-handler e (:src @!sci-ctx))
|
||||
(error/error-handler e (:src (store/get-ctx)))
|
||||
(throw e))))
|
||||
|
||||
(defn register-plugin! [_plug-in-name sci-opts]
|
||||
(swap! !sci-ctx sci/merge-opts sci-opts))
|
||||
(store/swap-ctx! sci/merge-opts sci-opts))
|
||||
|
||||
(defn- eval-script-tags* [script-tags]
|
||||
(when-let [tag (first script-tags)]
|
||||
|
|
@ -84,7 +85,7 @@
|
|||
(let [response (gobject/get this "response")]
|
||||
(gobject/set tag "scittle_id" src)
|
||||
;; save source for error messages
|
||||
(swap! !sci-ctx assoc-in [:src src] response)
|
||||
(store/swap-ctx! assoc-in [:src src] response)
|
||||
(sci/binding [sci/file src]
|
||||
(eval-string response)))
|
||||
(eval-script-tags* (rest script-tags)))))]
|
||||
|
|
@ -92,7 +93,7 @@
|
|||
(if-let [text (not-empty (str/trim (gobject/get tag "textContent")))]
|
||||
(let [scittle-id (str (gensym "scittle-tag-"))]
|
||||
(gobject/set tag "scittle_id" scittle-id)
|
||||
(swap! !sci-ctx assoc-in [:src scittle-id] text)
|
||||
(store/swap-ctx! assoc-in [:src scittle-id] text)
|
||||
(sci/binding [sci/file scittle-id]
|
||||
(eval-string text))
|
||||
(eval-script-tags* (rest script-tags)))
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
(ns scittle.nrepl
|
||||
(:require
|
||||
[clojure.edn :as edn]
|
||||
[sci.ctx-store :as store]
|
||||
[sci.nrepl.completions :refer [completions]]
|
||||
[sci.nrepl.info :refer [info]]
|
||||
[scittle.core :refer [!last-ns eval-string !sci-ctx]]))
|
||||
[scittle.core :refer [!last-ns eval-string]]))
|
||||
|
||||
(defn nrepl-websocket []
|
||||
(.-ws_nrepl js/window))
|
||||
|
|
@ -29,7 +30,7 @@
|
|||
:status ["error" "done"]})))))
|
||||
|
||||
(defn handle-nrepl-info [msg]
|
||||
(let [info (info (assoc msg :ctx @!sci-ctx))]
|
||||
(let [info (info (assoc msg :ctx (store/get-ctx)))]
|
||||
(nrepl-reply msg info)))
|
||||
|
||||
(declare ops)
|
||||
|
|
@ -61,13 +62,13 @@
|
|||
:eldoc handle-nrepl-info
|
||||
:lookup handle-nrepl-info
|
||||
:describe handle-describe
|
||||
:complete (fn [msg] (let [completions (completions (assoc msg :ctx @!sci-ctx))]
|
||||
:complete (fn [msg] (let [completions (completions (assoc msg :ctx (store/get-ctx)))]
|
||||
(nrepl-reply msg completions)))})
|
||||
|
||||
(defn handle-nrepl-message [msg]
|
||||
(if-let [handler (ops (:op msg))]
|
||||
(handler msg)
|
||||
(nrepl-reply (merge msg {:status ["error" "done"] :err "unkown-op"}) (assoc msg :ctx @!sci-ctx))))
|
||||
(nrepl-reply (merge msg {:status ["error" "done"] :err "unkown-op"}) (assoc msg :ctx (store/get-ctx)))))
|
||||
|
||||
(defn ws-url [host port path]
|
||||
(str "ws://" host ":" port "/" path))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue