Skip to content
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

Add complete-flush-caches command to force clear Compliment's caches #397

Merged
merged 1 commit into from
Mar 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[org.tcrawley/dynapath "0.2.5"]
^:source-dep [mvxcvi/puget "1.0.1"]
^:source-dep [fipp "0.6.6"]
^:source-dep [compliment "0.3.2"]
^:source-dep [compliment "0.3.3"]
^:source-dep [cljs-tooling "0.2.0"]
^:source-dep [cljfmt "0.5.6" :exclusions [org.clojure/clojurescript]]
^:source-dep [org.clojure/java.classpath "0.2.3"]
Expand Down
13 changes: 11 additions & 2 deletions src/cider/nrepl/middleware/complete.clj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[cider.nrepl.middleware.util.error-handling :refer [with-safe-transport]]
[cider.nrepl.middleware.util.misc :as u]
[compliment.core :as jvm-complete]
[compliment.utils :as jvm-complete-utils]
[cljs-tooling.complete :as cljs-complete]))

(defn complete
Expand All @@ -31,12 +32,18 @@
[msg]
{:completion-doc (completion-doc msg)})

(defn flush-caches-reply
[msg]
(jvm-complete-utils/flush-caches)
{})

(defn wrap-complete
"Middleware that looks up possible functions for the given (partial) symbol."
[handler]
(with-safe-transport handler
"complete" complete-reply
"complete-doc" doc-reply))
"complete-doc" doc-reply
"complete-flush-caches" flush-caches-reply))

(set-descriptor!
#'wrap-complete
Expand All @@ -54,4 +61,6 @@
{:doc "Retrieve documentation suitable for display in completion popup"
:requires {"ns" "The symbol's namespace"
"symbol" "The symbol to lookup"}
:returns {"completion-doc" "Symbol's documentation"}}}}))
:returns {"completion-doc" "Symbol's documentation"}}
"complete-flush-caches"
{:doc "Forces the completion backend to repopulate all its caches"}}}))
5 changes: 5 additions & 0 deletions test/clj/cider/nrepl/middleware/complete_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
(is (= (:status response) #{"done"}))
(is (.startsWith (:completion-doc response) "clojure.core/true?\n([x")))))

(deftest complete-flush-caches-test
(testing "basic usage"
(let [response (session/message {:op "complete-flush-caches"})]
(is (= (:status response) #{"done"})))))

(deftest error-handling-test
(testing "complete op error handling"
(with-redefs [c/complete (fn [& _] (throw (Exception. "complete-exc")))]
Expand Down