Skip to content

Commit 1367b25

Browse files
vemvbbatsov
authored andcommitted
PR feedback
1 parent e014c51 commit 1367b25

File tree

2 files changed

+41
-32
lines changed

2 files changed

+41
-32
lines changed

cider-eldoc.el

+7-6
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,13 @@ if the maximum number of sexps to skip is exceeded."
323323
(defun cider-eldoc-thing-type (eldoc-info)
324324
"Return the type of the ELDOC-INFO being displayed by eldoc.
325325
It can be a function or var now."
326-
(pcase (lax-plist-get eldoc-info "type")
327-
("function" 'fn)
328-
("special-form" 'special-form)
329-
("macro" 'macro)
330-
("method" 'method)
331-
("variable" 'var)))
326+
(or (pcase (lax-plist-get eldoc-info "type")
327+
("function" 'fn)
328+
("special-form" 'special-form)
329+
("macro" 'macro)
330+
("method" 'method)
331+
("variable" 'var))
332+
'fn))
332333

333334
(defun cider-eldoc-info-at-point ()
334335
"Return eldoc info at point.

test/cider-eldoc-tests.el

+34-26
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,16 @@
6969
(expect (cider--eldoc-format-class-names class-names)
7070
:to-equal "(String StringBuffer CharSequence & 1 more)")))))
7171

72+
;; NOTE: more cases could be added. Correct behavior is TBD, see https://github.com/clojure-emacs/orchard/issues/99
7273
(describe "cider-eldoc-thing-type"
7374
(it "Identifies special forms correctly"
7475
(let ((eldoc-info '("type" "special-form")))
7576
(expect (cider-eldoc-thing-type eldoc-info) :to-equal 'special-form)))
7677
(it "Identifies functions correctly"
7778
(let ((eldoc-info '("type" "function")))
79+
(expect (cider-eldoc-thing-type eldoc-info) :to-equal 'fn)))
80+
(it "Defaults to 'fn"
81+
(let ((eldoc-info '("type" "made-up-123")))
7882
(expect (cider-eldoc-thing-type eldoc-info) :to-equal 'fn))))
7983

8084
(describe "cider-eldoc-format-special-form"
@@ -89,16 +93,13 @@
8993
(cider-eldoc-format-special-form 'if 0 eldoc-info)
9094
(expect 'cider-eldoc-format-arglist :to-have-been-called-with '(("test" "then" "else?")) 0)))
9195
(it "Should not remove duplicates from special-form arglists that do not have duplicates"
92-
(let ((eldoc-info '("ns" nil
93-
"symbol" "."
94-
"arglists" ((".instanceMember" "instance" "args*") (".instanceMember" "Classname" "args*") ("Classname/staticMethod" "args*") ("Classname/staticField"))
95-
"type" "special-form")))
96+
(let* ((arglists '((".instanceMember" "instance" "args*") (".instanceMember" "Classname" "args*") ("Classname/staticMethod" "args*") ("Classname/staticField")))
97+
(eldoc-info `("ns" nil
98+
"symbol" "."
99+
"arglists" ,arglists
100+
"type" "special-form")))
96101
(cider-eldoc-format-special-form 'if 0 eldoc-info)
97-
(expect 'cider-eldoc-format-arglist :to-have-been-called-with '((".instanceMember" "instance" "args*")
98-
(".instanceMember" "Classname" "args*")
99-
("Classname/staticMethod" "args*")
100-
("Classname/staticField"))
101-
0))))
102+
(expect 'cider-eldoc-format-arglist :to-have-been-called-with arglists 0))))
102103

103104
(describe "cider-eldoc-format-thing"
104105
:var (class-names)
@@ -274,25 +275,32 @@
274275
(spy-on 'cider-connected-p :and-return-value t)
275276
(spy-on 'cider-eldoc--edn-file-p :and-return-value nil))
276277
(it "Should call cider-eldoc-format-variable for vars"
277-
(spy-on 'cider-eldoc-info-in-current-sexp :and-return-value '("thing" "foo" "pos" 0 "eldoc-info" ("ns" "clojure.core" "symbol" "foo" "type" "variable" "docstring" "test docstring")))
278-
(spy-on 'cider-eldoc-format-variable)
279-
(cider-eldoc)
280-
(expect 'cider-eldoc-format-variable :to-have-been-called-with "foo" '("ns" "clojure.core" "symbol" "foo" "type" "variable" "docstring" "test docstring")))
278+
(let* ((info '("ns" "clojure.core" "symbol" "foo" "type" "variable" "docstring" "test docstring")))
279+
(spy-on 'cider-eldoc-info-in-current-sexp :and-return-value `("thing" "foo" "pos" 0 "eldoc-info" ,info))
280+
(spy-on 'cider-eldoc-format-variable)
281+
(cider-eldoc)
282+
(expect 'cider-eldoc-format-variable :to-have-been-called-with "foo" info)))
283+
281284
(it "Should call cider-eldoc-format-special-form for special forms"
282-
(spy-on 'cider-eldoc-info-in-current-sexp :and-return-value '("thing" "if" "pos" 0 "eldoc-info" ("ns" "clojure.core" "symbol" "if" "type" "special-form" "arglists" ("special form arglist"))))
283-
(spy-on 'cider-eldoc-format-special-form)
284-
(cider-eldoc)
285-
(expect 'cider-eldoc-format-special-form :to-have-been-called-with "if" 0 '("ns" "clojure.core" "symbol" "if" "type" "special-form" "arglists" ("special form arglist"))))
285+
(let* ((info '("ns" "clojure.core" "symbol" "if" "type" "special-form" "arglists" ("special form arglist"))))
286+
(spy-on 'cider-eldoc-info-in-current-sexp :and-return-value `("thing" "if" "pos" 0 "eldoc-info" ,info))
287+
(spy-on 'cider-eldoc-format-special-form)
288+
(cider-eldoc)
289+
(expect 'cider-eldoc-format-special-form :to-have-been-called-with "if" 0 info)))
290+
286291
(it "Should call cider-eldoc-format-function for functions"
287-
(spy-on 'cider-eldoc-info-in-current-sexp :and-return-value '("thing" "a-fn" "pos" 0 "eldoc-info" ("ns" "foo.bar" "symbol" "a-fn" "type" "function" "arglists" ("function arglist"))))
288-
(spy-on 'cider-eldoc-format-function)
289-
(cider-eldoc)
290-
(expect 'cider-eldoc-format-function :to-have-been-called-with "a-fn" 0 '("ns" "foo.bar" "symbol" "a-fn" "type" "function" "arglists" ("function arglist"))))
292+
(let* ((info '("ns" "foo.bar" "symbol" "a-fn" "type" "function" "arglists" ("function arglist"))))
293+
(spy-on 'cider-eldoc-info-in-current-sexp :and-return-value `("thing" "a-fn" "pos" 0 "eldoc-info" ,info))
294+
(spy-on 'cider-eldoc-format-function)
295+
(cider-eldoc)
296+
(expect 'cider-eldoc-format-function :to-have-been-called-with "a-fn" 0 info)))
297+
291298
(it "Should call cider-eldoc-format-function for macros"
292-
(spy-on 'cider-eldoc-info-in-current-sexp :and-return-value '("thing" "a-macro" "pos" 0 "eldoc-info" ("ns" "clojure.core" "symbol" "a-macro" "type" "macro" "arglists" ("macro arglist"))))
293-
(spy-on 'cider-eldoc-format-function)
294-
(cider-eldoc)
295-
(expect 'cider-eldoc-format-function :to-have-been-called-with "a-macro" 0 '("ns" "clojure.core" "symbol" "a-macro" "type" "macro" "arglists" ("macro arglist")))))
299+
(let* ((info '("ns" "clojure.core" "symbol" "a-macro" "type" "macro" "arglists" ("macro arglist"))))
300+
(spy-on 'cider-eldoc-info-in-current-sexp :and-return-value `("thing" "a-macro" "pos" 0 "eldoc-info" ,info))
301+
(spy-on 'cider-eldoc-format-function)
302+
(cider-eldoc)
303+
(expect 'cider-eldoc-format-function :to-have-been-called-with "a-macro" 0 info))))
296304

297305
(describe "cider-eldoc-format-sym-doc"
298306
:var (eldoc-echo-area-use-multiline-p)
@@ -364,6 +372,6 @@
364372
(it "adds the datomic query inputs of the query at point to the arglist"
365373
(spy-on 'cider-second-sexp-in-list :and-return-value t)
366374
(spy-on 'cider-sync-request:eldoc-datomic-query
367-
:and-return-value '(dict "inputs" (("$" "?first-name"))))
375+
:and-return-value '(dict "inputs" (("$" "?first-name"))))
368376
(expect (cider--eldoc-add-datomic-query-inputs-to-arglists '(("query" "&" "inputs")))
369377
:to-equal '(("query" "$" "?first-name")))))

0 commit comments

Comments
 (0)