diff --git a/src/eval/deps_try/rr_service.clj b/src/eval/deps_try/rr_service.clj index 7c411ac..7e6f511 100644 --- a/src/eval/deps_try/rr_service.clj +++ b/src/eval/deps_try/rr_service.clj @@ -1,6 +1,10 @@ (ns eval.deps-try.rr-service (:require [babashka.fs :as fs] + [clojure.java.basis] + [clojure.string :as str] + [compliment.core] + [compliment.utils] [rebel-readline.clojure.line-reader :as clj-reader] [rebel-readline.clojure.service.local :as local-service] [rebel-readline.tools :as tools])) @@ -46,6 +50,22 @@ (ensure-fresh-examples-cache! examples-file-name {:max-age (duration->millis {:weeks 2})}) ((requiring-resolve 'orchard.clojuredocs/resolve-and-find-doc) wns wname))))) +(defn- classpath-for-completions + "This 'fixes' two things with compliment.utils/classpath: + - it removes cwd from the classpath which can simply yield too many options (e.g. ~) + - it picksup added libraries" + [] + (let [java-cp-sans-cwd (rest (str/split (System/getProperty "java.class.path") #":")) + basis-cp (->> (clojure.java.basis/current-basis) + :libs + vals + (mapcat :paths))] + (into java-cp-sans-cwd basis-cp))) + +(defmethod clj-reader/-complete ::service [_self word options] + (with-redefs [compliment.utils/classpath classpath-for-completions] + (doall (compliment.core/completions word options)))) + (defn create ([] (create nil)) ([options] diff --git a/src/eval/deps_try/try.clj b/src/eval/deps_try/try.clj index 48bfdea..8ca7a06 100644 --- a/src/eval/deps_try/try.clj +++ b/src/eval/deps_try/try.clj @@ -15,6 +15,9 @@ (require '[babashka.fs :as fs] :reload) +(defn- warm-up-completion-cache! [] + (clj-line-reader/-complete {:rebel-readline.service/type ::rebel-service/service} "nil" {})) + (defmethod rebel-readline/command-doc :deps/try [_] (str "Add dependencies (e.g. `:deps/try metosin/malli`)")) @@ -23,7 +26,8 @@ (if (seq args) (let [{:keys [deps error]} (try-deps/parse-dep-args (map str args))] (if-not error - ((requiring-resolve 'clojure.repl.deps/add-libs) deps) + (do ((requiring-resolve 'clojure.repl.deps/add-libs) deps) + (warm-up-completion-cache!)) (rebel-tools/display-error error))) (rebel-tools/display-warning "Usage: :deps/try metosin/malli \"0.9.2\" https://github.com/user/project some-ref \"~/some/project\""))) @@ -101,12 +105,8 @@ (defn- load-slow-deps! [] - (doto - (Thread. #(do - (require 'cljfmt.core) - (require 'compliment.core))) - (.setDaemon true) - (.start))) + (require 'cljfmt.core) + (warm-up-completion-cache!)) (defn -main []