cider
cider copied to clipboard
Cider completion style is invalid
Hi Bozhidar!
Cider adds a custom cider completion style to the completion-styles-alist. However the entry that is being added does not follow the required specification of completion-styles. This issue has been found by @manuel-uberti (see https://github.com/minad/corfu/issues/8 for the original issue). I wonder how cider gets away with the current implementation. Does the default completion-at-point function work with Cider?
Daniel
(defun cider-company-unfiltered-candidates (string &rest _)
"Return CIDER completion candidates for STRING as is, unfiltered."
(cider-complete string))
(add-to-list 'completion-styles-alist
'(cider
cider-company-unfiltered-candidates
cider-company-unfiltered-candidates
"CIDER backend-driven completion style."))
- The first function should follow the calling convention of
completion-try-completion, it should return t, nil or a pair (newstr.newpoint) - The second function should follow
completion-all-completions(I think it follows the spec, but you are not returning a base size in the last cdr which is okay I guess?)
Does the default completion-at-point function work with Cider?
Yeah, it does. This code is one of the oldest parts of CIDER and has seen minimal changes in the past 9 years, so I'm assuming that some APIs might have changed in Emacs. Is there some documentation on the topic that I can peruse?
The docstrings of completion-try-completion and completion-all-completions should have all the necessary information.
I see. So basically we need some cider-completion-try-completion function alongside the existing one. I guess I'll also have to check what are the benefits/use-cases of all the params we've suppressed for cider-company-unfiltered-candidates, as I see the actual definition has a lot of params:
(completion-all-completions STRING TABLE PRED POINT &optional METADATA)
Btw, I've also forgotten what's the difference between completion-at-point-functions and completion-styles-alist. Perhaps @dgutov can help by suggesting what'd be the appropriate changes.
@bbatsov Completions functions return some data from their own set, completion styles filter the data provided by the former.
I haven't written any completion styles myself, though, so I'm not going to help with the exact diff.
I was mostly wondering if those completion styles have anything to do with company-mode, but I guess I'll figure this out myself when I find a bit of time.
Looking at the surrounding code - this was some hack to enable fuzzy completion in company-mode:
(defun cider-company-unfiltered-candidates (string &rest _)
"Return CIDER completion candidates for STRING as is, unfiltered."
(cider-complete string))
(add-to-list 'completion-styles-alist
'(cider
cider-company-unfiltered-candidates
cider-company-unfiltered-candidates
"CIDER backend-driven completion style."))
(defun cider-company-enable-fuzzy-completion ()
"Enable backend-driven fuzzy completion in the current buffer."
(setq-local completion-styles '(cider)))
It is okay to effectively disable the completion style given that your backend already performs the filtering. However the functions should still follow the specifications, as I noted only the return value of the try-completion function is incorrect. cider-company-unfiltered-candidates is only valid as all-completions function.
Looking at the surrounding code - this was some hack to enable fuzzy completion in
company-mode:(defun cider-company-unfiltered-candidates (string &rest _) "Return CIDER completion candidates for STRING as is, unfiltered." (cider-complete string)) (add-to-list 'completion-styles-alist '(cider cider-company-unfiltered-candidates cider-company-unfiltered-candidates "CIDER backend-driven completion style.")) (defun cider-company-enable-fuzzy-completion () "Enable backend-driven fuzzy completion in the current buffer." (setq-local completion-styles '(cider)))
It was probably depending on my settings, but without hooking cider-company-enable-fuzzy-completion into cider-mode-hook I was never able to get Company completion in my CLJ/CLJC/CLJS buffers.