Skip to content

Commit

Permalink
Ensure ns-query map is built correctly
Browse files Browse the repository at this point in the history
The required structure for the 'query/var' function is `{:var-query
{:ns-query {...}}`. The older implementation did not grab those
keywords from the cider message and put them at the correct
level. they were left top level and then missed by the
`query/namespace` function.

In addition to this, there was a bug in orchard which had the wrong
prefix for inlined deps so these were not omitted in _2_ places: both
in the client-side specification of which namespaces to ignore and
orchard's own mechanism to elide cider's internal namespaces.

See related:
- orchard clojure-emacs/orchard#59
- CIDER clojure-emacs/cider#2658
  • Loading branch information
dan sutton authored and bbatsov committed Jun 25, 2019
1 parent e18afd4 commit 7b94bc7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

### Bugs fixed

* [#618](https://github.com/clojure-emacs/cider-nrepl/pull/618): Fix apropos to honor exclude-regexps to filter out namespaces by regex
* [#605](https://github.com/clojure-emacs/cider-nrepl/pull/605): Fix `ns-vars-with-meta` to return public vars.

### Changes
Expand Down
14 changes: 10 additions & 4 deletions src/cider/nrepl/middleware/apropos.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

;;; ## Middleware

(defn apropos [msg]
{:apropos-matches
(apropos/find-symbols
(defn- msg->var-query-map [msg]
(let [ns-query (select-keys msg [:exactly :project? :load-project-ns? :has-tests?
:include-regexps :exclude-regexps])]
(cond-> msg
;; Compatibility for the pre-var-query API
(:privates? msg)
Expand All @@ -28,11 +28,17 @@
(:docs? msg)
(assoc :full-doc? true)

true
(assoc-in [:var-query :ns-query] ns-query)

true
(update :var-query util.coerce/var-query)

(:ns msg)
(update :ns (comp find-ns symbol))))})
(update :ns (comp find-ns symbol)))))

(defn apropos [msg]
{:apropos-matches (-> msg msg->var-query-map apropos/find-symbols)})

(defn handle-apropos [handler msg]
(with-safe-transport handler msg
Expand Down
17 changes: 16 additions & 1 deletion test/clj/cider/nrepl/middleware/apropos_test.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(ns cider.nrepl.middleware.apropos-test
(:require
[cider.nrepl.middleware.apropos :refer [apropos]]
[cider.nrepl.middleware.apropos :refer [apropos] :as apropos]
[cider.nrepl.test-session :as session]
[clojure.string :as str]
[clojure.test :refer :all]))
Expand All @@ -9,6 +9,14 @@

(use-fixtures :each session/session-fixture)

(deftest msg->var-query-map-test
(testing "Constructs the ns-query map correctly"
(let [msg {:exclude-regexps ["^cider.nrepl" "^refactor-nrepl" "^nrepl"]
:query "spelling"}
query-map (#'apropos/msg->var-query-map msg)]
(is (contains? (:var-query query-map) :ns-query))
(is (= 3 (count (-> query-map :var-query :ns-query :exclude-regexps)))))))

(deftest integration-test
(testing "Apropos op, typical case"
(let [response (session/message {:op "apropos" :query "handle-apropos"})
Expand All @@ -17,6 +25,13 @@
(is (= (:type match) "function"))
(is (= (:name match) "cider.nrepl.middleware.apropos/handle-apropos"))))

(testing "Exclude namespaces typical case"
(let [response (session/message {:op "apropos" :query "handle-apropos"
:exclude-regexps ["cider.nrepl.middleware.apropos"]})
match (get-in response [:apropos-matches 0])]
(is (empty? match))
(is (= (:status response) #{"done"}))))

(testing "Apropos op, but specialized cases (invoked with prefix argument)"
(testing "Fails to get a private var because private? unset"
(let [response (session/message {:op "apropos" :query "my-private-var"})
Expand Down

0 comments on commit 7b94bc7

Please sign in to comment.