summaryrefslogtreecommitdiff
path: root/cider-eldoc.el
diff options
context:
space:
mode:
authorBozhidar Batsov <bozhidar@batsov.com>2016-04-08 10:30:10 +0300
committerBozhidar Batsov <bozhidar@batsov.com>2016-04-08 10:30:10 +0300
commitb91de64b72faa9aa440d451461922e3d078f4241 (patch)
treea0f1d7745bd7a28d686d3d0ccc62bc885b17b60b /cider-eldoc.el
parentfbbc0e742b4815e63a30710e54efa3cc7043cd25 (diff)
Add a hack to handle properly keywords at function positions in ns macros
The code in this function got pretty ugly, so it definitely needs some refactoring down the road.
Diffstat (limited to 'cider-eldoc.el')
-rw-r--r--cider-eldoc.el66
1 files changed, 36 insertions, 30 deletions
diff --git a/cider-eldoc.el b/cider-eldoc.el
index f7f228dc..8dfc046f 100644
--- a/cider-eldoc.el
+++ b/cider-eldoc.el
@@ -150,36 +150,42 @@ if the maximum number of sexps to skip is exceeded."
(defun cider-eldoc-info (thing)
"Return the info for THING.
This includes the arglist and ns and symbol name (if available)."
- (when (and (cider-nrepl-op-supported-p "eldoc")
- thing
- ;; ignore empty strings
- (not (string= thing ""))
- ;; ignore strings
- (not (string-prefix-p "\"" thing))
- ;; ignore regular expressions
- (not (string-prefix-p "#" thing))
- ;; ignore chars
- (not (string-prefix-p "\\" thing))
- ;; ignore numbers
- (not (string-match-p "^[0-9]" thing)))
- ;; check if we can used the cached eldoc info
- (cond
- ;; handle keywords for map access
- ((string-prefix-p ":" thing) (list nil thing '(("map") ("map" "not-found"))))
- ;; handle Classname. by displaying the eldoc for new
- ((string-match-p "^[A-Z].+\\.$" thing) (list nil thing '(("args*"))))
- ;; generic case
- (t (if (equal thing (car cider-eldoc-last-symbol))
- (cdr cider-eldoc-last-symbol)
- (when-let ((eldoc-info (cider-sync-request:eldoc thing)))
- (let ((arglist (nrepl-dict-get eldoc-info "eldoc"))
- (ns (nrepl-dict-get eldoc-info "ns"))
- (symbol (nrepl-dict-get eldoc-info "name")))
- ;; middleware eldoc lookups are expensive, so we
- ;; cache the last lookup. This eliminates the need
- ;; for extra middleware requests within the same sexp.
- (setq cider-eldoc-last-symbol (list thing ns symbol arglist))
- (list ns symbol arglist))))))))
+ (let ((thing (pcase thing
+ (":import" "clojure.core/import")
+ (":refer-clojure" "clojure.core/refer-clojure")
+ (":use" "clojure.core/use")
+ (":refer" "clojure.core/refer")
+ (_ thing))))
+ (when (and (cider-nrepl-op-supported-p "eldoc")
+ thing
+ ;; ignore empty strings
+ (not (string= thing ""))
+ ;; ignore strings
+ (not (string-prefix-p "\"" thing))
+ ;; ignore regular expressions
+ (not (string-prefix-p "#" thing))
+ ;; ignore chars
+ (not (string-prefix-p "\\" thing))
+ ;; ignore numbers
+ (not (string-match-p "^[0-9]" thing)))
+ ;; check if we can used the cached eldoc info
+ (cond
+ ;; handle keywords for map access
+ ((string-prefix-p ":" thing) (list nil thing '(("map") ("map" "not-found"))))
+ ;; handle Classname. by displaying the eldoc for new
+ ((string-match-p "^[A-Z].+\\.$" thing) (list nil thing '(("args*"))))
+ ;; generic case
+ (t (if (equal thing (car cider-eldoc-last-symbol))
+ (cdr cider-eldoc-last-symbol)
+ (when-let ((eldoc-info (cider-sync-request:eldoc thing)))
+ (let ((arglist (nrepl-dict-get eldoc-info "eldoc"))
+ (ns (nrepl-dict-get eldoc-info "ns"))
+ (symbol (nrepl-dict-get eldoc-info "name")))
+ ;; middleware eldoc lookups are expensive, so we
+ ;; cache the last lookup. This eliminates the need
+ ;; for extra middleware requests within the same sexp.
+ (setq cider-eldoc-last-symbol (list thing ns symbol arglist))
+ (list ns symbol arglist)))))))))
(defun cider-eldoc ()
"Backend function for eldoc to show argument list in the echo area."