Bogus snippet completions suggested #19967
Replies: 6 comments 4 replies
-
I cannot reproduce in VSCode, so this is probably something about your LSP client not properly supporting snippets. |
Beta Was this translation helpful? Give feedback.
-
It's the LSP which sends the bogus auto-completion suggestions in this context. What exactly do you mean by "properly supporting snippets"? |
Beta Was this translation helpful? Give feedback.
-
Did you check the response manually? What is it? Given it works in VSCode I suspect it's not the case.
I dunno, not properly implementing them or something. |
Beta Was this translation helpful? Give feedback.
-
These are postfix snippets. When you select e.g. the |
Beta Was this translation helpful? Give feedback.
-
Continuing #19968 here as indicated. I'll copy-paste the issue here to provide context: > rust-analyzer --version
rust-analyzer 2025.05.19
> rustc -V
rustc 1.87.0 (17067e9ac 2025-05-09) (Alpine Linux 1.87.0-r0)
> nvim --version
NVIM v0.11.1
Build type: MinSizeRel
LuaJIT 2.1.1723681758
``
**code snippet to reproduce**:
```rust
fn main() {
let s = String::new();
s.
} Please the cursor at the end of line s. and trigger auto-completion. rust-analyzer suggests a bunch of snippets: let~ letm, ref~, box~, etc… When using the "expand" shortcut, these snippets are expanded to things like These suggestions don't make sense in this context; if I type The main issue at hand, is that these suggestions (about a dozen) drown out the actually relevant suggestions; one that are consistent to what I've just typed. These suggestions should only be shown when they are consistent with what one has typed in the code editor. @ChayimFriedman2 mentioned that this issue is not evident in VSCode simply due to implementation details of the presentational UI.
It depends on what you use for the UI itself. I'm using nvim-cmp, which uses the following criteria to sort items: It seems that I think trying to re-order irrelevant suggestions so they're not in the way is not the ideal fix for this; it would be best to simply avoid generating irrelevant suggestions. |
Beta Was this translation helpful? Give feedback.
-
We tell the clients how to sort based on semantics information, which they don't have. If clients choose to ignore this and override our hints, there is nothing we can do. Arguably, that's a bug in nvim-cmp. As @flodiebold said, those completions are often helpful (at least with correct sorting) and therefore we will not disable them by default; you can do that for your own if you want. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
code snippet to reproduce:
Please the cursor at the end of line
s.
and trigger auto-completion. rust-analyzer suggests a bunch of snippets:let~
letm
,ref~
,box~
, etc…All of these are completely bogus in this context. For example,
box~
expands toBox::new
. The result of applying it is:This isn't even valid syntax. These snippets suggestions are completely ignoring context (are they a new feature? I've never seen them before), and add a lot of noise. In most situations, actually valid suggestions are buried behind a bunch of suggestions that don't make sense.
In these situations, snippets should not be suggested; contextual suggestions (like methods on the String type) should be the only suggestions.
Beta Was this translation helpful? Give feedback.
All reactions