-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Use completion item indices instead of property matching when searching for the completion item to resolve #18503
Use completion item indices instead of property matching when searching for the completion item to resolve #18503
Conversation
…ng for the completion item to resolve
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.
We could also include detail
in the comparison, right? But I hope the completion order is deterministic, let's give this a try and see if it breaks horribly.
Alas, not really, as we do resolve rust-analyzer/crates/rust-analyzer/src/lsp/to_proto.rs Lines 339 to 344 in aabab29
which means that the "original item" will always have Due to the same idea, |
We'll want to backport this commit to beta. |
[beta] backports - Use completion item indices instead of property matching rust-lang#132987, rust-lang/rust-analyzer#18503 - Reject raw lifetime followed by `'`, like regular lifetimes do rust-lang#132341 - Only disable cache if predicate has opaques within it rust-lang#132625 - rustdoc-search: case-sensitive only when capitals are used rust-lang#133043 r? cuviper
[beta] backports - Use completion item indices instead of property matching rust-lang#132987, rust-lang/rust-analyzer#18503 - Reject raw lifetime followed by `'`, like regular lifetimes do rust-lang#132341 - Only disable cache if predicate has opaques within it rust-lang#132625 - rustdoc-search: case-sensitive only when capitals are used rust-lang#133043 - (ci) Update macOS Xcode to 15 rust-lang#131570 r? cuviper
I encountered an autocompletion error in Neovim and bisected to this PR. In the following function, when I type "ma" and select fn hello(s: String) {
s. // type ma
} |
I don't have a working nvim setup, but I couldn't reproduce this either of Code, Helix, or Zed. |
@DianQK does hrsh7th/cmp-nvim-lsp#75 fix things for you? |
I can confirm that it doesn't resolve this, but it has resolved another problem where function parameters were not being auto-completed. It changes |
I have no clue what Nvim does so special, alas, but good that it fixes some things. From my side, can also add that emacs + lsp-mode worked what I was testing this PR, and Zed works. |
I don’t fully understand the code or know exactly where the issue lies. However, I believe that the root cause is not in this PR. From the logs, I observed that when Nvim switches between completion candidates, it sends a I maybe have resolved the issue by modifying For reference: https://github.com/hrsh7th/nvim-cmp/blob/f17d9b4394027ff4442b298398dfcaab97e40c4f/lua/cmp/view/native_entries_view.lua#L130. |
So, every time you scroll through the completions, a new "edit" request is issued? rust-analyzer completion resolution relies on the fact that completions being resolved are from the same, unchanged document as the original, unresolved completions came. This is according to the example from the LSP spec: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_completion
I have a few questions on top:
|
I don't know about the other questions. Since this is an option, I don't think this is an issue. I could create a discussion about this. |
…ocompleting See rust-lang/rust-analyzer#18503 and hrsh7th/cmp-nvim-lsp#72 for more info
I think some swift action is needed here - this was backported to 1.83 which is due for release in three days (@traviscross @cuviper), but it seems to have introduced a pretty severe bug: |
@BoxyUwU is handling the final release process this time. The stable candidate was already prepared in rust-lang/rust#133445, but it should be possible to respin that, if the rust-analyzer team figures out what they want soon. |
I think 3 days is definitely not enough to cook a proper fix. We should revert #18167 and try again after stable (at least, revert for stable). @lnicola @SomeoneToIgnore your thoughts? |
I didn't really understand the new issue (the screencaps look fine to me?). Is it worse than #18363? |
This looks like what is arguably a client issue to me. Neovim and Helix seem to edit the text document when selecting completions and afterwards try to resolve the previous completions; at least that's what I suspect. The spec doesn't outright say this is forbidden, but I don't think it makes sense for completion items to still be valid after modifying the document. Still, reverting the PR on stable might be a good idea. |
I think given how little time we have, reverting the PR is the safest option. For the next release we can decide whether it's client's fault and we want to re-introduce the changes as-is, or whether we want to do something to help them. |
Do note that you'll have to revert both related PRs then, as they cause different kinds of troubles. nvim has a way to fix this (according to #18503 (comment)) but no one on the nvim side seems interested, as even hrsh7th/cmp-nvim-lsp#75 is not merged yet, and this is a fix of a clear violation of the LSP spec on the nvim side. I suspect the current editing situation is closer to the client error too, as all other editors including Kate get it right. |
@SomeoneToIgnore As you seem to know what the correct reverts are to post, can you PR them to rust-lang/rust:stable and ping @BoxyUwU? |
I can sure try in a few hours when back to the keyboard. Another (IMO, better) proposal could be a forward-fix, that forces r-a to resolve all 3 problematic, completion-related, properties always (as it was doing before along with all other properties), leaving the rest bloated ones like Would that be a feasible middle-ground and something people are willing to try? |
No, there will be no "forward-fixes" right before rolling the stable release. |
To be clear, if the revert is accepted, it will not be with 3 days on the clock. It will be with essentially negative time on the clock: the process of generating stable release artifacts is already underway. So any revert lands only at Boxy's discretion.
|
If the r-a team thinks a revert would be a good idea and a PR to stable is opened very quickly then it's definitely doable. There is really not much time though since we have to have time to rebuild the artifacts which only really leaves a day or so to decide if this is actually something the r-a team would want to backport and then actually get the PR opened. I would not want to land anything other than a revert of the involved PRs though as if there is anything wrong with the backport it would be not feasible to backport another thing. |
cc @rust-lang/rust-analyzer if someone could make an explicit decisive decision as to whether a revert should be backported that'd be great :3 |
TIL that rust repo does not seem to use r-a as a submodule, so I had to create reverse-patches manually, and manually apply them. Here's the PR: rust-lang/rust#133476 The compilation error:
I'm attaching the patches I've used, and if I was mistaken along the way, I'd be very grateful for a helping hand. |
@BoxyUwU revert away. I'll |
…vidbarsky [stable(not yet) backport] Revert r-a completions breakage This PR revers recent completion-related changes in r-a, which caused nvim and helix to malfunction. Changes reverted: 1. rust-lang/rust-analyzer#18167 2. rust-lang/rust-analyzer#18247 3. rust-lang/rust-analyzer#18503 See rust-lang/rust-analyzer#18503 (comment) for more context cc `@BoxyUwU`
Part of #18363
Closes #18501
Previously, completions for resolution were re-queried with the same completion parameters, and then picked by matching their properties as
this is incorrect, as
completion.deprecated == original_completion.deprecated
check may never success due to the property being unresolved initially (other properties are fine and are not resolved)So, instead, follow a less fragile approach: since we resolve completions for the same document state and same query, we can rely on the
Vec<CompletionItem>
order to return the same set of the completion items, in the same order.This is also fragile, but seems to work and definitely works better than the previous version.
It would be great to see if we can derive a better "id" for such items, but I'm clueless here.
If this approach does not seem to be good, we'd better follow #18501 path and revert this entirely (bringing back tons of useless json in responses though)
cc @traviscross