Skip to content

Bug Report: Code completion when implementing functions in VSCode doesn't work properly. #11467

@CalinZBaenen

Description

@CalinZBaenen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-completionautocompletionA-lspLSP conformance issues and missing featuresC-bugCategory: bugE-unknownIt's unclear if the issue is E-hard or E-easy without digging in

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions