Fix [#babashka.nrepl/66](babashka/babashka.nrepl#66) (#1630)

This commit is contained in:
Michiel Borkent 2023-09-28 14:55:59 +02:00 committed by GitHub
parent 8788a3c482
commit d1580f1a72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 6 deletions

View file

@ -17,6 +17,7 @@ A preview of the next release can be installed from
- [#1624](https://github.com/babashka/babashka/pull/1624): Use Oracle GraalVM 21 ([@lispyclouds](https://github.com/lispyclouds))
- Use PGO to speed up loops (now 2-3x faster for `(time (loop [val 0 cnt 10000000] (if (pos? cnt) (recur (inc val) (dec cnt)) val)))`!)
- Bump babashka.cli to 0.7.53
- Fix [#babashka.nrepl/66](https://github.com/babashka/babashka.nrepl/issues/66)
## 1.3.184 (2023-08-22)

View file

@ -74,7 +74,7 @@
(defn split-classpath
"Returns the classpath as a seq of strings, split by the platform
specific path separator."
([^String cp] (vec (.split cp path-sep))))
([^String cp] (vec (when cp (.split cp path-sep)))))
(defn get-classpath
"Returns the current classpath as set by --classpath, BABASHKA_CLASSPATH and add-classpath."

View file

@ -1,11 +1,18 @@
(ns babashka.impl.nrepl-server
{:no-doc true}
(:require
[babashka.impl.classpath :as cp]
[babashka.impl.clojure.core :as core-extras]
[babashka.impl.common :as common]
[babashka.nrepl.impl.server :refer [process-msg]]
[babashka.nrepl.server :as server]
[sci.core :as sci]))
(defmethod process-msg :classpath [rf result m]
(rf result {:response {"status" ["done"]
"classpath" (cp/split-classpath (cp/get-classpath))}
:response-for (:msg m)}))
(defn start-server!
([]
(start-server! nil))

View file

@ -1,14 +1,16 @@
(ns babashka.impl.nrepl-server-test
(:require
[babashka.fs :as fs]
[babashka.impl.nrepl-server :refer [start-server!]]
[babashka.nrepl.server :refer [parse-opt stop-server!]]
[babashka.main :as main]
[babashka.nrepl.server :refer [parse-opt stop-server!]]
[babashka.test-utils :as tu]
[babashka.wait :as wait]
[bencode.core :as bencode]
[clojure.test :as t :refer [deftest is testing]]
[sci.core :as sci]
[sci.ctx-store :as ctx-store])
[sci.ctx-store :as ctx-store]
[babashka.impl.classpath :as cp])
(:import
[java.lang ProcessBuilder$Redirect]))
@ -31,6 +33,9 @@
res)
res (if-let [status (:sessions res)]
(assoc res :sessions (mapv bytes->str status))
res)
res (if-let [cp (:classpath res)]
(assoc res :classpath (mapv bytes->str cp))
res)]
res))
@ -189,7 +194,17 @@
(bencode/write-bencode os {"op" "eval" "code" "(set! *unchecked-math* true)"
"session" session "id" (new-id!)})
(let [reply (read-reply in session @id)]
(is (= "true" (:value reply))))))))
(is (= "true" (:value reply)))))
(testing "classpath op"
(cp/add-classpath "src:test")
(bencode/write-bencode os {"op" "classpath"
"session" session "id" (new-id!)})
(let [reply (read-reply in session @id)
cp (:classpath reply)]
(is (every? string? cp))
(is (pos? (count cp)))
;; dev-resources doesn't exist
(is (pos? (count (filter fs/exists? cp)))))))))
(deftest ^:skip-windows nrepl-server-test
(let [proc-state (atom nil)
@ -221,5 +236,4 @@
;;;; Scratch
(comment
)
(comment)