-
-
Notifications
You must be signed in to change notification settings - Fork 645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cider completion style is invalid #3006
Comments
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 |
I see. So basically we need some
|
Btw, I've also forgotten what's the difference between |
@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 |
Looking at the surrounding code - this was some hack to enable fuzzy completion in (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 |
It was probably depending on my settings, but without hooking |
I've been taking a look at this, probably it would take some work to do. And so far, it appears that I will have to change somethings in nrepl, to fix #3019 correctly and make it work with orderless and other (any?) completion styles. |
I will! From what I could already gather, the In the basic style it works because everything you type is considered a prefix, since it doesn't try to match stuff fuzzy-ly, it (kinda) makes sense. In this weekend I will try to mess with nrepl itself. Btw, there's a easier way to debug elisp? I've been just using |
You could perhaps We also have the nrepl log ( |
I also have a particular stance for the overall issue (and related issues) - if the
This way we can cleanly swap implementations without risks/breakage. The old one, valid or not, works well for many people and isn't a frequent source of complaints. IMO without a clear understanding (and summary, for others) of how Emacs expect things to work, and how we tackled those requirements, we'll remain in the same messy situation for another batch of years. It's not a small task, but probably not huge either. |
I guess few people use advanced features, that's why few people have noticed the issues that currently exist. I don't think it'd be particularly risky to iterate on the current codebase, as it's not complex.
That's the main issue for me - there's no clear documentation about implementing the completion APIs, so getting things right usually requires researching "reference" implementation and trying to figure out what's expected from us. I've often thought about doing a deeper dive there, but never found the time and the desire to do so. I recall I wrote the original completion code in less than 1 hour with minimal research, so it's definitely not rocket science. I also recall I barely touched it since then. 😅 Before someone really analyzes what needs to be done it'd be premature to discuss alternative implementations and so on. |
Yes, at the moment similarly I don't have the particular time or personal desire of iterating on this. Although I'd be happy for a variety of users to be supported.
Exactly - someone interested in taking this to the next level would have to make quite the ansaysis - namely a full-stack one:
(of course, happy to help with whatever we can) Finally, perhaps Emacs lsp implementations (especially the official one) may be a good 'reference' implementation, if docs don't suffice. |
This comment summarizes one of the problems really well: #3019 (comment). Here's what I understood so far:
(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.")) So, a completion style is a list of symbol (partial-completion
completion-pcm-try-completion completion-pcm-all-completions)
(defun completion-pcm-all-completions (string table pred point)
(pcase-let ((`(,pattern ,all ,prefix ,_suffix)
(completion-pcm--find-all-completions string table pred point)))
(when all
(nconc (completion-pcm--hilit-commonality pattern all)
(length prefix))))) See that So, overall, this mismatch can be easily fixed in CIDER and we should do that. |
This is problem number 2: Several Emacs completion styles (new prepackaged |
Problem number 3: Other Emacs prepackaged completion styles (like
|
That's where I'd try to make CIDER intervene in some way - in other words, bridge both worlds smartly. We could try to stay compliant with flex/orderless. But when CIDER hits Compliment, it does send all the relevant info (e.g. we override the prefix from empty to actual user input, and we possibly pass the completion style as a separate k-v). In the end, it's always CIDER that creates nrepl communication - we are in control. Whenever that happens we can inspect what the user was typing (assuming that flex/orderless hide that from us). |
If we are sure about that, I'd be happy to document that specifically (we already have documented that misc styles are currently unsupported - but we can double down on that). |
I gathered that from a cursory analysis I did today. I tried setting different default completion styles, observe what happens in CIDER<->cider-nrepl interaction and what gets suggested by I've noticed just now that there are some ways to customize them, e.g. there is |
Thanks (and kudos) 👍
Yeah it would be odd if completions were only useful for Elisp. Emacs has always been a multi-lang editor. |
That'd be great. Fantastic analysis, btw! Seems to me it'd be best to start with 1), as it's probably the easiest item to address. |
Sorry, disregard what I said above. The delim regex that it generates includes multiple characters, so it indeed completes So, overall, I'd say that most default completion styles ( The ideal solution for me personally (and subjectively) would be the following
|
I'd only suggest to not introduce breakage in, for instance, the following forms:
i.e. the current behavior is pretty correct for practical purposes - it works for what can work and actively prevents unsupported stuff from being activated. The next-gen solution can live under a separate name and out of the defaults, at least during one release. (For clarity, I'd personally be happy to enable it / give feedback from day 1). Most of all, I'd try to keep users isolated from churn and ensure that they always have a known-good "escape hatch" if there were surprises. |
First, I don't think CIDER should need a custom completion style, my understanding is that, the CIDER completion style was a "hack" to make fuzzy completion work (correct me if I'm wrong). I think the main problem is in Lines 197 to 203 in 380073e
See how that is implemented in eglot: It's getting the prefix from another place (lsp magic stuff probably, not that clear to me) Same thing in haskell mode, but easier to understand: So, I think the way CIDER is sending the prefix to nrepl is incorrect. I'm thinking on a right way of grabbing the prefix in a decent way (maybe Anyways, I think we should open a discussion topic. |
Yeah, more or less.
Feel free to do so. |
Sure thing! Anyone encountering this issue should check out https://docs.cider.mx/cider/usage/code_completion.html#completion-styles |
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 minad/corfu#8 for the original issue). I wonder how cider gets away with the current implementation. Does the defaultcompletion-at-point
function work with Cider?Daniel
completion-try-completion
, it should return t, nil or a pair (newstr.newpoint)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?)The text was updated successfully, but these errors were encountered: