From 99d63130a1b6c543dcf1b83a3a41f59489ffe89b Mon Sep 17 00:00:00 2001 From: dan sutton Date: Sun, 23 Jun 2019 12:35:06 -0500 Subject: [PATCH] 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 https://github.com/clojure-emacs/orchard/pull/59/ - CIDER https://github.com/clojure-emacs/cider/pull/2658 --- CHANGELOG.md | 1 + src/cider/nrepl/middleware/apropos.clj | 14 ++++++++++---- .../clj/cider/nrepl/middleware/apropos_test.clj | 17 ++++++++++++++++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92720c1bb..045ad4ac2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/cider/nrepl/middleware/apropos.clj b/src/cider/nrepl/middleware/apropos.clj index 4f07ac3b8..4b52150a3 100644 --- a/src/cider/nrepl/middleware/apropos.clj +++ b/src/cider/nrepl/middleware/apropos.clj @@ -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) @@ -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 diff --git a/test/clj/cider/nrepl/middleware/apropos_test.clj b/test/clj/cider/nrepl/middleware/apropos_test.clj index eceaa85b6..931114616 100644 --- a/test/clj/cider/nrepl/middleware/apropos_test.clj +++ b/test/clj/cider/nrepl/middleware/apropos_test.clj @@ -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])) @@ -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"}) @@ -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"})