Skip to content

Commit 176a8e7

Browse files
[completion] Cache last result of cider-complete
1 parent 380073e commit 176a8e7

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

cider-completion.el

+28-20
Original file line numberDiff line numberDiff line change
@@ -184,26 +184,34 @@ performed by `cider-annotate-completion-function'."
184184
(when-let* ((bounds (bounds-of-thing-at-point 'symbol)))
185185
(when (and (cider-connected-p)
186186
(not (or (cider-in-string-p) (cider-in-comment-p))))
187-
(list (car bounds) (cdr bounds)
188-
(lambda (prefix pred action)
189-
;; When the 'action is 'metadata, this lambda returns metadata about this
190-
;; capf, when action is (boundaries . suffix), it returns nil. With every
191-
;; other value of 'action (t, nil, or lambda), 'action is forwarded to
192-
;; (complete-with-action), together with (cider-complete), prefix and pred.
193-
;; And that function performs the completion based on those arguments.
194-
;;
195-
;; This api is better described in the section
196-
;; '21.6.7 Programmed Completion' of the elisp manual.
197-
(cond ((eq action 'metadata) `(metadata (category . cider))) ;; defines a completion category named 'cider, used later in our `completion-category-overrides` logic.
198-
((eq (car-safe action) 'boundaries) nil)
199-
(t (with-current-buffer (current-buffer)
200-
(complete-with-action action
201-
(cider-complete prefix) prefix pred)))))
202-
:annotation-function #'cider-annotate-symbol
203-
:company-kind #'cider-company-symbol-kind
204-
:company-doc-buffer #'cider-create-compact-doc-buffer
205-
:company-location #'cider-company-location
206-
:company-docsig #'cider-company-docsig))))
187+
(let* (last-prefix
188+
last-result
189+
(complete
190+
(lambda (prefix)
191+
(unless (string-equal last-prefix prefix)
192+
(setq last-prefix prefix)
193+
(setq last-result (cider-complete prefix)))
194+
last-result)))
195+
(list (car bounds) (cdr bounds)
196+
(lambda (prefix pred action)
197+
;; When the 'action is 'metadata, this lambda returns metadata about this
198+
;; capf, when action is (boundaries . suffix), it returns nil. With every
199+
;; other value of 'action (t, nil, or lambda), 'action is forwarded to
200+
;; (complete-with-action), together with (cider-complete), prefix and pred.
201+
;; And that function performs the completion based on those arguments.
202+
;;
203+
;; This api is better described in the section
204+
;; '21.6.7 Programmed Completion' of the elisp manual.
205+
(cond ((eq action 'metadata) `(metadata (category . cider))) ;; defines a completion category named 'cider, used later in our `completion-category-overrides` logic.
206+
((eq (car-safe action) 'boundaries) nil)
207+
(t (with-current-buffer (current-buffer)
208+
(complete-with-action action
209+
(funcall complete prefix) prefix pred)))))
210+
:annotation-function #'cider-annotate-symbol
211+
:company-kind #'cider-company-symbol-kind
212+
:company-doc-buffer #'cider-create-compact-doc-buffer
213+
:company-location #'cider-company-location
214+
:company-docsig #'cider-company-docsig)))))
207215

208216
(defun cider-completion-flush-caches ()
209217
"Force Compliment to refill its caches.

0 commit comments

Comments
 (0)