rust-analyzer: Bug Report: Code completion when implementing functions in VSCode doesn't work properly.
Specs.
In Visual Studio Code, I have suspicion that Rust Analyzer’s code completion isn’t working as intended.
Here’s some specs:
Rust-Analyzer Version: 7a17fb9c4 2022-02-13 nightly
RustUp Version: rustup 1.24.3 (2021-11-09)
RustC Version: rustc 1.58.1 (db9d1b20b 2022-01-20)
VSCode Version: 1.64.0, 5554b12acf27056905806867f251c859323ff7e9, x64
Enabled VSCode Extensions: "Rust Analyzer", "GitLens"
VSCode Vendor:
Operating System: Arch (x86_64)
Desktop Environment: XFCE4
Description.
As far as I can tell, only one prediction (pattern) doesn’t work, though, similar bugs may be present in other forms.
Whenever I try to implement a trait onto a datatype I have (for this example’s purposes Trait onto S*), when implementing the functions in Trait, no predictions come up when I start writing "fn " (with a space at the end); even if I add the first letter(s) of a function name.
Reproduction.
Example:
trait Trait {
fn test() -> String;
}
struct S;
impl Trait for S {
// I START WRITING HERE...
}
When I replace // I START WRITING HERE... with fn t, with my cursor and focus still in the textarea of VSCode, no predictions pop up.
However, instead of writing fn t, if I just start writing te; for example, then the prediction fn test() -> String comes up. (Even though it should work in only the former OR both scenarios.)
I can tell it’s not strictly a VSCode bug, because when I do Ctrl + Space, I’m told “No suggestions.”.
Working Example.
This bug came up while I was working on my game RuntDeale.
I had a trait, Positioned, in position.rs. After using Positioned in sprites.rs (sibling of position.rs), I was implementing Positioned for Sprite<'_, T> (specific implementation details not important*).
This is the point I found the bug, entering the impl block, typing away, noticing fn se didn’t trigger the completion for fn setX(&mut self, x:Scalar) -> ().
Temporary Workaround.
There is an “assist” that’s provided, nicked “Implement Missing Members”, which works fine.
But it implements everything at once, which is overwhelming for me. - I usually work on each function one at a time.
Exception.
This bug is not apparent in at-least one setup, in NioVim, according to testimonial @olestrohm:

About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 22 (11 by maintainers)
Commits related to this issue
- Merge #11967 11967: fix: Fix trait impl completions not triggering after `fn`/`const`/`type` r=jonas-schievink a=jonas-schievink . This is against the language server protocol, we need change this so that we only send a replacement with a single line in the main text edit, and add the followings lines to theadditionalTextEditsas insertions.