From d1580f1a723b55a1c2d0ba678151ce4ea8b87e33 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Thu, 28 Sep 2023 14:55:59 +0200 Subject: [PATCH] Fix [#babashka.nrepl/66](babashka/babashka.nrepl#66) (#1630) --- CHANGELOG.md | 1 + src/babashka/impl/classpath.clj | 2 +- src/babashka/impl/nrepl_server.clj | 7 +++++++ test/babashka/impl/nrepl_server_test.clj | 24 +++++++++++++++++++----- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f6bcab0..65d483c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/babashka/impl/classpath.clj b/src/babashka/impl/classpath.clj index 76c76dfb..6da8b59f 100644 --- a/src/babashka/impl/classpath.clj +++ b/src/babashka/impl/classpath.clj @@ -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." diff --git a/src/babashka/impl/nrepl_server.clj b/src/babashka/impl/nrepl_server.clj index d670d91a..ab3c0c28 100644 --- a/src/babashka/impl/nrepl_server.clj +++ b/src/babashka/impl/nrepl_server.clj @@ -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)) diff --git a/test/babashka/impl/nrepl_server_test.clj b/test/babashka/impl/nrepl_server_test.clj index 3166e434..0fdecb89 100644 --- a/test/babashka/impl/nrepl_server_test.clj +++ b/test/babashka/impl/nrepl_server_test.clj @@ -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)