Skip to content

Commit 2f8429d

Browse files
committed
Adjust the ClojureDocs middleware resolve the symbols its been given
1 parent d23c83f commit 2f8429d

File tree

4 files changed

+31
-15
lines changed

4 files changed

+31
-15
lines changed

project.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
:scm {:name "git" :url "https://github.com/clojure-emacs/cider-nrepl"}
77

88
:dependencies [[nrepl "0.6.0"]
9-
^:inline-dep [cider/orchard "0.5.0-beta13"]
9+
^:inline-dep [cider/orchard "0.5.0-beta14"]
1010
^:inline-dep [thunknyc/profile "0.5.2"]
1111
^:inline-dep [mvxcvi/puget "1.1.2"]
1212
^:inline-dep [fipp "0.6.18"] ; can be removed in unresolved-tree mode

src/cider/nrepl.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,11 +487,11 @@
487487
:returns {"status" "\"ok\" if reloading was successful"}}
488488
"clojuredocs-lookup"
489489
{:doc "Return a map of information in ClojureDocs."
490-
:requires {"ns" "The namespace where `symbol` is define."
491-
"symbol" "The symbol to lookup."}
490+
:requires {"ns" "The namespace where `sym` will be resolved."
491+
"sym" "The symbol to lookup."}
492492
:optional {"export-edn-url" "EDN file URL exported from ClojureDocs. Defaults to \"https://clojuredocs-edn.netlify.com/export.compact.edn\"."}
493493
:returns {"clojuredocs" "A map of information in ClojureDocs."
494-
"status" "\"no-document\" if there is no document matching to `ns` and `symbol`."}}}})
494+
"status" "\"no-doc\" if there is no document matching to `ns` and `symbol`."}}}})
495495

496496
;;; Cider's Handler
497497

src/cider/nrepl/middleware/clojuredocs.clj

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@
44
[cider.nrepl.middleware.util.error-handling :refer [with-safe-transport]]
55
[orchard.clojuredocs :as docs]))
66

7-
(defn- clojuredocs-lookup-reply [{:keys [export-edn-url ns symbol]}]
8-
(if-let [doc (if export-edn-url
9-
(docs/find-doc ns symbol export-edn-url)
10-
(docs/find-doc ns symbol))]
11-
{:clojuredocs (util/transform-value doc)}
12-
{:status :no-document}))
7+
(defn- clojuredocs-lookup-reply [{:keys [export-edn-url ns sym]}]
8+
(try
9+
(if-let [doc (if export-edn-url
10+
;; TODO: change this to `resolve-doc` once I've added the extra arity there
11+
(docs/resolve-and-find-doc (symbol ns) (symbol sym) export-edn-url)
12+
(docs/resolve-and-find-doc (symbol ns) (symbol sym)))]
13+
{:clojuredocs (util/transform-value doc)}
14+
{:status :no-doc})
15+
;; TODO: Handle a missing ns directly in Orchard
16+
(catch Exception e
17+
{:status :no-doc})))
1318

1419
(defn clojuredocs-refresh-cache-reply [{:keys [export-edn-url]}]
1520
(docs/clean-cache!)

test/clj/cider/nrepl/middleware/clojuredocs_test.clj

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,31 @@
2121
(is (contains? (:status response) "ok")))))
2222

2323
(deftest clojuredocs-lookup-integration-test
24-
(testing "Find not existing document"
24+
(testing "Searching for non-existing documentation"
2525
(let [response (session/message {:op "clojuredocs-lookup"
2626
:ns "non-existing"
27-
:symbol "non-existing"
27+
:sym "non-existing"
2828
:export-edn-url test-url})]
29-
(is (contains? (:status response) "no-document"))))
29+
(is (contains? (:status response) "no-doc"))))
3030

31-
(testing "Find existing document"
31+
(testing "Searching for existing documentation"
3232
(let [response (session/message {:op "clojuredocs-lookup"
3333
:ns "clojure.core"
34-
:symbol "first"
34+
:sym "first"
3535
:export-edn-url test-url})
3636
doc (get response :clojuredocs {})]
3737
(is (contains? (:status response) "done"))
3838
(is (= "clojure.core" (:ns doc)))
3939
(is (= "first" (:name doc)))
40+
(is (every? #(contains? doc %) [:examples :see-alsos]))))
41+
42+
(testing "Resolves syms in the supplied ns"
43+
(let [response (session/message {:op "clojuredocs-lookup"
44+
:ns "cider.nrepl.middleware.clojuredocs-test"
45+
:sym "map"
46+
:export-edn-url test-url})
47+
doc (get response :clojuredocs {})]
48+
(is (contains? (:status response) "done"))
49+
(is (= "clojure.core" (:ns doc)))
50+
(is (= "map" (:name doc)))
4051
(is (every? #(contains? doc %) [:examples :see-alsos])))))

0 commit comments

Comments
 (0)