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: Testimony of the bug.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 22 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Son of a b#@$%

image

Forgive me, for I have sinned.

Changed the value, everything started working…

Thank you.

Ok, so apparently you don’t get any completions at all? This is indeed a separate issue then. Some things to check when you report a new issue would be:

  • does pressing Ctrl+Space do anything? even if rust-analyzer isn’t working, you’d expect VSCode’s text suggestions to show up unless they’re disabled.
  • do you have quick suggestions enabled in the VSCode settings?
  • do any other completions work? e.g. if you type let x = 1; x. and press Ctrl+Space?

We currently send a completion with one text edit that replaces the text range at from fn keyword to cursor position with a replacement text that spans multiple lines(contains newlines). 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 the additionalTextEdits as insertions.