emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/cider f422665fb0: Populate completions with metadata (#322


From: ELPA Syncer
Subject: [nongnu] elpa/cider f422665fb0: Populate completions with metadata (#3226)
Date: Thu, 28 Jul 2022 01:58:06 -0400 (EDT)

branch: elpa/cider
commit f422665fb0491abb9d8a8fdc2ce1aebb2497d6d3
Author: Cássio Ávila <cassioavila@protonmail.com>
Commit: GitHub <noreply@github.com>

    Populate completions with metadata (#3226)
    
    This makes it possible to override the cider completion style in 
completion-category-defaults or completion-category-overrides.
---
 CHANGELOG.md                                      |  1 +
 cider-completion.el                               | 15 ++++++++++++++-
 doc/modules/ROOT/pages/usage/code_completion.adoc | 12 ++++++++++++
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5291ffb405..703a7c5926 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@
 
 ### New features
 
+- [#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`.
 - [#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.
 
 ## Changes
diff --git a/cider-completion.el b/cider-completion.el
index 2611eb26f6..3461d55e67 100644
--- a/cider-completion.el
+++ b/cider-completion.el
@@ -237,7 +237,20 @@ performed by `cider-annotate-completion-function'."
     (when (and (cider-connected-p)
                (not (or (cider-in-string-p) (cider-in-comment-p))))
       (list (car bounds) (cdr bounds)
-            (completion-table-dynamic #'cider-complete)
+            (lambda (prefix pred action)
+              ;; When the 'action is 'metadata, this lambda returns metadata 
about this
+              ;; capf, when action is (boundaries . suffix), it returns nil. 
With every
+              ;; other value of 'action (t, nil, or lambda), 'action is 
forwarded to
+              ;; (complete-with-action), together with (cider-complete), 
prefix and pred.
+              ;; And that function performs the completion based on those 
arguments.
+              ;;
+              ;; This api is better described in the section
+              ;; '21.6.7 Programmed Completion' of the elisp manual.
+              (cond ((eq action 'metadata) `(metadata (category . cider)))
+                    ((eq (car-safe action) 'boundaries) nil)
+                    (t (with-current-buffer (current-buffer)
+                         (complete-with-action action
+                                               (cider-complete prefix) prefix 
pred)))))
             :annotation-function #'cider-annotate-symbol
             :company-kind #'cider-company-symbol-kind
             :company-doc-buffer #'cider-create-doc-buffer
diff --git a/doc/modules/ROOT/pages/usage/code_completion.adoc 
b/doc/modules/ROOT/pages/usage/code_completion.adoc
index 782df2ce12..ef76139e0e 100644
--- a/doc/modules/ROOT/pages/usage/code_completion.adoc
+++ b/doc/modules/ROOT/pages/usage/code_completion.adoc
@@ -115,6 +115,18 @@ image::completion-annotations.png[Completion Annotations]
 TIP: Completion annotations can be disabled by setting
 `cider-annotate-completion-candidates` to `nil`.
 
+=== Changing the completion style
+
+Sometimes the user may want to use a different completion style just for the 
CIDER
+complete at point function. That can be achieved by setting
+`completion-category-defaults`, overriting the completion style of the CIDER
+complete at point function. The following snippet accomplishes that:
+
+[source,lisp]
+----
+(add-to-list 'completion-category-defaults '(cider (styles basic)))
+----
+
 === Updating stale classes and methods cache
 
 Sometimes, the completion fails to recognize new classes that came with



reply via email to

[Prev in Thread] Current Thread [Next in Thread]