-
-
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
Grab the completion prefix correctly #3659
Conversation
This PR makes the CIDER completions behave correctly and minimizes round trips to nrepl to gather completions. Tested with the `flex` and `orderless` completion styles. What should we do with `cider-company-enable-fuzzy-completion`? With this we can remove the CIDER completion style. Should `cider-company-enable-fuzzy-completion` just mirror the behaviour of `cider-enable-flex-completion`?
Hi @toniz4 ! Thanks much for your efforts. Caching / redundant trip avoidance was recently tackled in https://github.com/clojure-emacs/cider/pull/3655/files . Had you noticed? From my side I don't quite have the time to go through it however I'd constructively suggest:
Once that's all clear, probably we'd appreciate unit tests for this area - it's a dense one and very few of us have the capability to maintain it in detail over the years. None of this is to discourage you - I'm simply trying to set up us all for success. Cheers - V |
Of course, I saw the commits made by @alexander-yakushev after I started working on this, but we kinda followed the same course. But in this PR I'm trying to address another issue, the way we are getting the prefix are insufficient. So I tried to take the string inside (defun cider--complete-with-cache (bounds)
"Return completions to the symbol at `BOUNDS' with caching.
If the completion of `bounds' is cached, return the cached completions,
otherwise, call `cider-complete', set the cache, and return the completions."
(cdr-safe
(if (and (consp cider--completion-cache)
(eq bounds (car cider--completion-cache)))
cider--completion-cache
(setq cider--completion-cache
`(,bounds . ,(cider-complete (buffer-substring (car bounds) (cdr bounds)))))))) But after some testing, this is also insufficient. The bounds is set when the completion starts. We can see in https://github.com/dgutov/robe/blob/6bc8a07fc483407971de0966d367a11006b3ab80/robe.el#L949-L952 |
If we're confident in the solution - I think yes. I don't want to kill I'll have to ponder a bit more on your PR, as I'm not sure I quite follow the issue with the bounds that it's trying to solve. Perhaps @alexander-yakushev will understand this better and have an easier time evaluating it. |
It also depends on how important the support for Emacs <27 is, I had an impression that there was also a compatibility dimension to this. |
In the latest commit, it passes all the "tests" @alexander-yakushev presented here #3653 (comment) Completing cji -> clojure.java.io Completing |
@toniz4 thanks for picking this up! You should take a look at #3655 for the context. It is crucial that the completion is as fresh as possible and correct too. We figured out there that being a closed over variable inside |
@alexander-yakushev Yeah, I think that's a better way to go. The way I implemented the functions looks cleaner, but I was not thinking about multiple sessions. But it would be really improbable to "hit" the cache even on another buffer, but it's possible. Either way, putting this stuff in a closure is the right way |
The CI is failing with:
You can ignore the integration tests, as something's wrong with their container images since last week. We'll have to address this separately. |
We should also probably add a comment in the code for this, so it won't get forgotten down the road. :-) |
Updated the function to keep basically the same caching behavior that @alexander-yakushev introduced. But it differs in the way we are getting the prefix for the completions. Kinda confusing having 2 things that serve as a prefix, but we are working with emacs. Upon reviewing other packages capf's, I observed that commonly they had a specific mechanism to retrieve the prefix, rather than directly using the prefix from the lambda. Another thing, I removed the hard coded style override, that were setting the basic completion style for CIDER completions. Is this ok? Currently it will use the completion style configured by the user (by default is |
That's fine by me (from what I got everything should work now, so those are completely redundant), but I'll leave it to @alexander-yakushev to decide how to proceed here. |
LGTM too! Once this is merged, I'll try using enable-flex again and see if there is any disparity with a custom completion style. |
About tests, @vemv do you have any idea how can we make unit tests for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking reasonable!
wrt unit tests, I don't have ideas at the moment. Might get back at it later today.
Either way I'd appreciate much if after the last round of feedback, you can try this branch over some 24-48 hours.
That QA-ing tends to catch most issues.
Yeah, using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Some final suggestions:
- I think the PR doesn't introduce caching anymore? If so please update PR title and description
- Please add a changelog entry
Cheers - V
Before merging, I would like to QA it more over the weekend. This week I was off work, so I couldn't test it in the real world. |
@toniz4 Sure. No rush. |
I've been testing this since Sunday, it seems to be working great! If there's no more reviews to be made, I think it's ready to merge. |
Awesome! Please merge master in first. |
Great work, kudos! I'll be sure to use Cider master just now to give it some extra QA. |
Thanks! Feel free to ping me if any problem appears |
Installed the latest MELPA Cider and switched to |
Excellent! Seems we can hard-deprecate the company-specific code then. |
By removing completely the completion style? And make the old function just echo the deprecation notice |
I'd pursue the path of least obstrusiveness, i.e. try to keep things functional, and echo things once at most (and not on every completion). Assuming that removing the cider completion style is a good idea, I still would keep it around assuming that it has no real cost. At least during the course of one stable release. Users rarely enjoy starting a work day to broken setups :) |
This code doesn't have a pure-Emacs equivalent and powers Company and Corfu:
|
yup, this is a valid implementation and should not be removed. I would just remove the competition style. But I agree on waiting a couple of stable releases first. |
We're talking about the It's not immediately obvious to me why it became redundant, mind to generously state here for posterity? Last but not least - great work! No surprises since I adopted this. Between this and @alexander-yakushev's improvements I'm pretty positive that it feels snappier (especially for the doc part). |
By my understanding and @bbatsov's confirmation, the completion style was made to fix flex completions in company. That was necessary because the complete-at-point function was not grabbing the prefix in a way that would be compatible with "flex-ish" competition styles. And by the analysis made by @minad in #3006, the completion style by itself does not follow the specifications of a completion style. But somehow it appears to work with company. The flex completion style has been on emacs for some years too. |
Another option is to fix the completion style making it compliant. But since I don't use it and testing anything involving completions in emacs is a PITA, I think I would let someone pickup that |
Thanks for the summary! A PR that marked all the now-redundant bits with comments would seem a good start. In that PR itself we can iterate over the preferred soft/hard deprecation mechanism. |
Yeah, that is what I was referring to. We can keep around other Anyways, none of this is particularly important. |
I think it's fine having the |
This PR makes the CIDER completions behave correctly. Reworking the method to grab the prefix in
cider-complete-at-point
. Making it compatible with "fuzzy" completion styles.Tested with the
flex
andorderless
completion styles.What should we do with
cider-company-enable-fuzzy-completion
? Withthis we can remove the CIDER completion style. Should
cider-company-enable-fuzzy-completion
just mirror the behavior ofcider-enable-flex-completion
?This also makes CIDER use the default completion style, instead of setting
completion-category-overrides
to make CIDER use the basic completion style.Before submitting the PR make sure the following things have been done (and denote this
by checking the relevant checkboxes):
eldev test
)eldev lint
) which is based onelisp-lint
and includescheckdoc
, check-declare, packaging metadata, indentation, and trailing whitespace checks.Thanks!
If you're just starting out to hack on CIDER you might find this section of its
manual extremely useful.