Skip to content

Commit 0e4e452

Browse files
author
dan sutton
committed
Ensure ns-query map is built correctly
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
1 parent a192066 commit 0e4e452

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/cider/nrepl/middleware/apropos.clj

+10-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
;;; ## Middleware
1010

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

31+
true
32+
(assoc-in [:var-query :ns-query] ns-query)
33+
3134
true
3235
(update :var-query util.coerce/var-query)
3336

3437
(:ns msg)
35-
(update :ns (comp find-ns symbol))))})
38+
(update :ns (comp find-ns symbol)))))
39+
40+
(defn apropos [msg]
41+
{:apropos-matches (-> msg msg->var-query-map apropos/find-symbols)})
3642

3743
(defn handle-apropos [handler msg]
3844
(with-safe-transport handler msg

test/clj/cider/nrepl/middleware/apropos_test.clj

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(ns cider.nrepl.middleware.apropos-test
22
(:require
3-
[cider.nrepl.middleware.apropos :refer [apropos]]
3+
[cider.nrepl.middleware.apropos :refer [apropos] :as apropos]
44
[cider.nrepl.test-session :as session]
55
[clojure.string :as str]
66
[clojure.test :refer :all]))
@@ -9,6 +9,14 @@
99

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

12+
(deftest msg->var-query-map-test
13+
(testing "Constructs the ns-query map correctly"
14+
(let [msg {:exclude-regexps ["^cider.nrepl" "^refactor-nrepl" "^nrepl"]
15+
:query "spelling"}
16+
query-map (#'apropos/msg->var-query-map msg)]
17+
(is (contains? (:var-query query-map) :ns-query))
18+
(is (= 3 (count (-> query-map :var-query :ns-query :exclude-regexps)))))))
19+
1220
(deftest integration-test
1321
(testing "Apropos op, typical case"
1422
(let [response (session/message {:op "apropos" :query "handle-apropos"})
@@ -17,6 +25,13 @@
1725
(is (= (:type match) "function"))
1826
(is (= (:name match) "cider.nrepl.middleware.apropos/handle-apropos"))))
1927

28+
(testing "Exclude namespaces typical case"
29+
(let [response (session/message {:op "apropos" :query "handle-apropos"
30+
:exclude-regexps ["cider.nrepl.middleware.apropos"]})
31+
match (get-in response [:apropos-matches 0])]
32+
(is (empty? match))
33+
(is (= (:status response) #{"done"}))))
34+
2035
(testing "Apropos op, but specialized cases (invoked with prefix argument)"
2136
(testing "Fails to get a private var because private? unset"
2237
(let [response (session/message {:op "apropos" :query "my-private-var"})

0 commit comments

Comments
 (0)