Skip to content

Commit

Permalink
[Fix clojure-emacs/cider#1493] Handle special forms in extract-eldoc
Browse files Browse the repository at this point in the history
The arglists of special forms are under the :forms metadata key (and
they have a slightly different format).
  • Loading branch information
bbatsov committed Jan 31, 2016
1 parent 1349a89 commit dadaeb2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/cider/nrepl/middleware/info.clj
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,15 @@
transport (response-for msg (u/err-info e :info-error))))))

(defn extract-eldoc [info]
(if (contains? info :candidates)
(->> (:candidates info)
vals
(mapcat :arglists)
distinct
(sort-by count))
(:arglists info)))
(cond
(:special-form info) (->> (:forms info)
(map vec))
(contains? info :candidates) (->> (:candidates info)
vals
(mapcat :arglists)
distinct
(sort-by count))
:else (:arglists info)))

(defn format-eldoc [raw-eldoc]
(map #(mapv str %) raw-eldoc))
Expand Down
8 changes: 7 additions & 1 deletion test/clj/cider/nrepl/middleware/info_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@
;;;; eldoc
(def test-eldoc-info {:arglists '([x] [x y])})

(def test-eldoc-info-special-form {:forms ['(if test then else?)]
:special-form true})

(def test-eldoc-info-candidates
{:candidates '{X {:arglists ([x])}
Y {:arglists ([x] [x y z])}
Expand All @@ -133,7 +136,9 @@
(deftest test-extract-eldoc
(is (= (info/extract-eldoc test-eldoc-info) '([x] [x y])))
(is (= (info/extract-eldoc test-eldoc-info-candidates)
'([] [x] [x y z]))))
'([] [x] [x y z])))
(is (= (info/extract-eldoc test-eldoc-info-special-form)
['(if test then else?)])))

(deftest test-format-eldoc
(is (= (info/format-eldoc (info/extract-eldoc test-eldoc-info)) '(["x"] ["x" "y"])))
Expand All @@ -143,6 +148,7 @@
(deftest test-eldoc
(is (info/eldoc {:ns "clojure.core" :symbol "map"}))
(is (info/eldoc {:ns "clojure.core" :symbol ".toString"}))
(is (info/eldoc {:ns "clojure.core" :symbol "if"}))
(is (not (info/eldoc {:ns "clojure.core" :symbol (gensym "non-existing")}))))

(deftest test-var-meta
Expand Down

0 comments on commit dadaeb2

Please sign in to comment.