Skip to content

Commit f422665

Browse files
authored
Populate completions with metadata (#3226)
This makes it possible to override the cider completion style in completion-category-defaults or completion-category-overrides.
1 parent b47fe53 commit f422665

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### New features
66

7+
- [#3226](https://github.com/clojure-emacs/cider/pull/3226): Populate completions metadata, making it possible to change the style of completion via `completion-category-override` or `completion-category-defaults`.
78
- [#2946](https://github.com/clojure-emacs/cider/issues/2946): Add custom var `cider-merge-sessions` to allow combining sessions in two different ways: Setting `cider-merge-sessions` to `'host` will merge all sessions associated with the same host within a project. Setting it to `'project` will combine all sessions of a project irrespective of their host.
89

910
## Changes

cider-completion.el

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,20 @@ performed by `cider-annotate-completion-function'."
237237
(when (and (cider-connected-p)
238238
(not (or (cider-in-string-p) (cider-in-comment-p))))
239239
(list (car bounds) (cdr bounds)
240-
(completion-table-dynamic #'cider-complete)
240+
(lambda (prefix pred action)
241+
;; When the 'action is 'metadata, this lambda returns metadata about this
242+
;; capf, when action is (boundaries . suffix), it returns nil. With every
243+
;; other value of 'action (t, nil, or lambda), 'action is forwarded to
244+
;; (complete-with-action), together with (cider-complete), prefix and pred.
245+
;; And that function performs the completion based on those arguments.
246+
;;
247+
;; This api is better described in the section
248+
;; '21.6.7 Programmed Completion' of the elisp manual.
249+
(cond ((eq action 'metadata) `(metadata (category . cider)))
250+
((eq (car-safe action) 'boundaries) nil)
251+
(t (with-current-buffer (current-buffer)
252+
(complete-with-action action
253+
(cider-complete prefix) prefix pred)))))
241254
:annotation-function #'cider-annotate-symbol
242255
:company-kind #'cider-company-symbol-kind
243256
:company-doc-buffer #'cider-create-doc-buffer

doc/modules/ROOT/pages/usage/code_completion.adoc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ image::completion-annotations.png[Completion Annotations]
115115
TIP: Completion annotations can be disabled by setting
116116
`cider-annotate-completion-candidates` to `nil`.
117117

118+
=== Changing the completion style
119+
120+
Sometimes the user may want to use a different completion style just for the CIDER
121+
complete at point function. That can be achieved by setting
122+
`completion-category-defaults`, overriting the completion style of the CIDER
123+
complete at point function. The following snippet accomplishes that:
124+
125+
[source,lisp]
126+
----
127+
(add-to-list 'completion-category-defaults '(cider (styles basic)))
128+
----
129+
118130
=== Updating stale classes and methods cache
119131

120132
Sometimes, the completion fails to recognize new classes that came with

0 commit comments

Comments
 (0)