-
-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix nrepl evaluating multi forms #604
base: main
Are you sure you want to change the base?
Conversation
I cheated and use The root cause of the bug was that the original implementation wasn't properly handling multiple forms in a single code string. Here's a breakdown: Original problematic code: (defn compile [the-val]
(let [{js-str :javascript
cljs-ns :ns
:as new-state} (compiler/compile-string* the-val {...})]
;; Only handles compiling as one big string
js-str))
(defn do-handle-eval [{:keys [ns code file] :as request} send-fn]
(->
(js/Promise.resolve code)
(.then compile) ;; <-- Problem: Tries to compile entire string at once
(.then (fn [v]
(js/eval v)))
...)) The issues were:
The fix addresses these by:
(defn read-forms [code]
(let [rdr (e/reader code)]
(loop [forms []]
(let [form (try
(e/parse-next rdr compiler/squint-parse-opts)
...)]
...))))
(reduce (fn [promise form]
(.then promise #(eval-form form send-fn request)))
(js/Promise.resolve nil)
forms)
(defn eval-form [form send-fn request]
(-> (js/Promise.resolve form)
(.then compile-form)
(.then (fn [val]
(send-fn request
{"ns" (str @last-ns)
"value" (format-value ...)})))
...)) |
819d59e
to
829a42c
Compare
It doesn't seem to contain existing code to test nrepl implementation; I tried to add some provided by LLM, but it's not clear to me what's the expected/correct response from a nrepl server. For example, below is a failing test case request {:code "(def x 1)\n(def y 2)\n(+ x y)", :id "1", :op "eval", :session "8bd3f28e-5f01-43d4-a1d2-6a601f21a8ca"}
... redacted ...
expected: (= ["#'user/x" "#'user/y" "3"] (->> responses (filter :value) (mapv :value)))
actual: (not (= ["#'user/x" "#'user/y" "3"] ["nil" "nil" "3"])) I could still push the tests if that could provide some help. |
On a second thought, I just made the tests to match current nrepl responses. Some caveats:
|
Please answer the following questions and leave the below in as part of your PR.
#603
This PR contains a test to prevent against future regressions
I have updated the CHANGELOG.md file with a description of the addressed issue.