diff options
author | tijsmallaerts <tijs.mallaerts@gmail.com> | 2017-03-22 09:49:40 +0100 |
---|---|---|
committer | Bozhidar Batsov <bozhidar.batsov@gmail.com> | 2017-03-22 09:55:21 +0100 |
commit | 0816372ff483dd92eb8775c76929835b0955ae70 (patch) | |
tree | 914130c3468fc8f939b24047bf44aa8724c5e6f6 /cider-eldoc.el | |
parent | d528100ecb1441933b0c9ef1920d147cf6c9a40b (diff) |
[Fix #1832] Add eldoc info for datomic query input parameters
Diffstat (limited to 'cider-eldoc.el')
-rw-r--r-- | cider-eldoc.el | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/cider-eldoc.el b/cider-eldoc.el index b7012b46..8af59508 100644 --- a/cider-eldoc.el +++ b/cider-eldoc.el @@ -86,6 +86,15 @@ displayed. When nil, always display eldoc for first symbol of the sexp." :group 'cider :package-version '(cider . "0.13.0")) +(defcustom cider-eldoc-display-context-dependent-info nil + "When non-nil, display context dependent info in the eldoc where possible. +CIDER will try to add expected function arguments based on the current context, +for example for the datomic.api/q function where it will show the expected +inputs of the query at point." + :type 'boolean + :group 'cider + :package-version '(cider . "0.15.0")) + (defun cider--eldoc-format-class-names (class-names) "Return a formatted CLASS-NAMES prefix string. CLASS-NAMES is a list of classes to which a Java interop form belongs. @@ -398,10 +407,23 @@ This includes the arglist and ns and symbol name (if available)." "arglists" arglists "docstring" docstring "type" type))) - ;; 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 eldoc-plist)) + ;; add context dependent args if requested by defcustom + ;; do not cache this eldoc info to avoid showing info + ;: of the previous context + (if cider-eldoc-display-context-dependent-info + (cond + ;; add inputs of datomic query + ((and (equal ns-or-class "datomic.api") + (equal name-or-member "q")) + (let ((arglists (lax-plist-get eldoc-plist "arglists"))) + (lax-plist-put eldoc-plist "arglists" + (cider--eldoc-add-datomic-query-inputs-to-arglists arglists)))) + ;; if none of the clauses is successful, do cache the eldoc + (t (setq cider-eldoc-last-symbol (list thing eldoc-plist)))) + ;; 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 eldoc-plist))) eldoc-plist)))))))) (defun cider--eldoc-remove-dot (sym) @@ -413,6 +435,24 @@ Only useful for interop forms. Clojure forms would be returned unchanged." "Check whether FILE-NAME is representing an EDN file." (and file-name (equal (file-name-extension file-name) "edn"))) +(defun cider--eldoc-add-datomic-query-inputs-to-arglists (arglists) + "Add the expected inputs of the datomic query to the ARGLISTS." + (if (cider-second-sexp-in-list) + (let* ((query (cider-second-sexp-in-list)) + (query-inputs (nrepl-dict-get + (cider-sync-request:eldoc-datomic-query query) + "inputs"))) + (if query-inputs + (thread-first + (thread-last arglists + (car) + (remove "&") + (remove "inputs")) + (append (car query-inputs)) + (list)) + arglists)) + arglists)) + (defun cider-eldoc () "Backend function for eldoc to show argument list in the echo area." (when (and (cider-connected-p) |