Search code examples
visual-studio-coderustautocompleterust-analyzerrust-rustlings

Getting auto completion work with rustlings in VSCodium?


I am running VSCodium version 1.85.2, rustc and rust-analyzer 1.76.0, and the rust-analyzer Visual Studio Code extension version 0.3.1839.

The extension is partially working. I get syntax errors, for example, from this code:

fn main() {
    let answer = current_favorite_color();
    println!("My current favorite color is {}", answer);
}

this doesn't belong here

fn current_favorite_color() -> String {
    String::from("blue")
}

It correctly produces 14 "problems", including:

Syntax Error: expected BANG rust-analyzer (syntax-error)
Syntax Error: expected `{`, `[`, `(` rust-analyzer (syntax-error)
Syntax Error: expected SEMICOLON rust-analyzer (syntax-error)

However, when I'm trying to type actual rust code, pressing ^-spacebar only gets me the "abc" suggestions. So, for example, I would expect typing answer. followed by ^-spacebar in the above code (assuming I remove the invalid code first) to get me a list that includes the trim function.

What do I need to do to get that working? Thanks!


Solution

  • The rustlings cli tool has a command to make rust-analyzer work on the exercise folder.

    rustlings lsp
    

    It will create a rust-project.json file

    This was mentioned in their README.