Skip to content

Commit

Permalink
Read multiple forms from input
Browse files Browse the repository at this point in the history
  • Loading branch information
dan sutton committed Dec 10, 2018
1 parent 06fcf78 commit 05fbaf9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
53 changes: 30 additions & 23 deletions src/cider/piggieback.clj
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,15 @@
(apply merge
((juxt :requires :require-macros)
(ana/get-namespace ana/*cljs-ns*)))]
(reader/read {:read-cond :allow :features #{:cljs}}
(readers/source-logging-push-back-reader
(java.io.StringReader. form-str))))))
(let [rdr (readers/source-logging-push-back-reader
(java.io.StringReader. form-str))
eof (Object.)]
(take-while #(not= % eof)
(repeatedly
#(reader/read {:read-cond :allow
:features #{:cljs}
:eof eof}
rdr)))))))

(defn eval-cljs [repl-env env form opts]
(cljs.repl/evaluate-form repl-env
Expand Down Expand Up @@ -242,26 +248,27 @@
special-fns (merge cljs.repl/default-special-fns (:special-fns repl-options))
is-special-fn? (set (keys special-fns))]
(try
(let [form (read-cljs-string code)
env (assoc (ana/empty-env) :ns (ana/get-namespace init-ns))
result (when form
(if (and (seq? form) (is-special-fn? (first form)))
(do ((get special-fns (first form)) repl-env env form repl-options)
nil)
(eval-cljs repl-env env form repl-options)))]
(.flush ^Writer *out*)
(.flush ^Writer *err*)
(when (and
(or (not ns)
(not= init-ns ana/*cljs-ns*))
ana/*cljs-ns*)
(swap! session assoc #'ana/*cljs-ns* ana/*cljs-ns*))
(transport/send
transport
(response-for msg
{:value (or result "nil")
:printed-value 1
:ns (@session #'ana/*cljs-ns*)})))
(let [forms (read-cljs-string code)]
(doseq [form forms]
(let [env (assoc (ana/empty-env) :ns (ana/get-namespace init-ns))
result (when form
(if (and (seq? form) (is-special-fn? (first form)))
(do ((get special-fns (first form)) repl-env env form repl-options)
nil)
(eval-cljs repl-env env form repl-options)))]
(.flush ^Writer *out*)
(.flush ^Writer *err*)
(when (and
(or (not ns)
(not= init-ns ana/*cljs-ns*))
ana/*cljs-ns*)
(swap! session assoc #'ana/*cljs-ns* ana/*cljs-ns*))
(transport/send
transport
(response-for msg
{:value (or result "nil")
:printed-value 1
:ns (@session #'ana/*cljs-ns*)})))))
(catch Throwable t
(repl-caught session transport msg t repl-env repl-options)))))))

Expand Down
6 changes: 6 additions & 0 deletions test/cider/piggieback_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,9 @@
(is (-> (nrepl/message *session* {:op "eval" :code "(defprotocol Foo [do-a-thing [this]])"})
nrepl/combine-responses
:value)))

(deftest handles-multiple-forms
(is (= ["#'cljs.user/x" "#'cljs.user/y"]
(-> (nrepl/message *session* {:op "eval" :code "(def x 1) (def y 2)" :ns "cljs.user"})
nrepl/combine-responses
:value))))

0 comments on commit 05fbaf9

Please sign in to comment.