Skip to content

Commit

Permalink
Improve completions
Browse files Browse the repository at this point in the history
- added libraries are picked up
- don't consider cwd for completions
  might yield too many results
- make warming completion-cache synchronous
  this prevents race-condition when completing before warming ends
  • Loading branch information
eval committed Jun 16, 2023
1 parent 6831ae1 commit 94ed4ac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
20 changes: 20 additions & 0 deletions src/eval/deps_try/rr_service.clj
Original file line number Diff line number Diff line change
@@ -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]))
Expand Down Expand Up @@ -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]
Expand Down
14 changes: 7 additions & 7 deletions src/eval/deps_try/try.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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`)"))

Expand All @@ -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\"")))

Expand Down Expand Up @@ -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 []
Expand Down

0 comments on commit 94ed4ac

Please sign in to comment.