English 中文(简体)
Rust Visual Studio Code code completion not working
原标题:

I m trying to learn Rust and installed the Rust extension for VSCode. But I m not seeing auto-completions for any syntax.

I d like to call .trim() on String but I get no completion for it. I read that the completion for Rust isn t great, but the Language Server should be able to recommend methods that can be called on a struct?

I also saw a tutorial where the tutor had autocompletion in VSCode but I don t know what extension he was using.

I also tried it in WSL and thought that WSL was the problem, but after also installing Gigabytes of Visual Studio Build Tools it turns out it s also not working natively on Windows.

enter image description here

最佳回答

As mentioned in dustypomerleau/rust-syntax issue 4, since Nov. 2020, the grammar is merged into Rust Analyzer, and RA s grammar overrides others when it starts.

The completion should improve, and the microsoft/vscode issue 64488 "Need a better grammar support for Rust lang" just got closed (Dec. 2020) as a result.

问题回答

None of the above answers worked for me.

After a lot of trials, below is what worked. I tested it for 2weeks and then wrote it here.

now code completion is working in every file.

[edit1] After a few months of usage if rust code completion is not working then...

  1. close the vs code
  2. go to the dir where the rust code is written
  3. delete cargo.lock .vscode folders
  4. open vs code > new window > and reimport the project.

I just had the same issue despite using the rust-analyzer extension. Somehow, the Cargo.toml of my current project was not linked to rust-analyzer s linked projects.

To link it, the path of the Cargo.toml must appear in {project_root}/.vscode/settings.json as an argument to rust-analyzer.linkedProjects. Here is how this looks like now in my case:

{
    "rust-analyzer.linkedProjects": [
        "./py-kernel-regression/Cargo.toml",
        "./Cargo.toml",
    ]
}

One more thing, if your file is not added to mod.rs VSCode will fail to recognize as a project file, and hence the autocomplete suggestions may not work.

Or in main.rs your module is not listed at the top:

mod file_model;
mod utils;
// add relevant module or file




相关问题
high load on mysql DB how to avoid?

I have a table contain the city around the worlds it contain more than 70,000 cities. and also have auto suggest input in my home page - which used intensively in my home page-, that make a sql query ...

Fast Javascript String Replacement

Hey there geniuses of SO! This is for an autocomplete plugin that needs to accept data as an array of arrays and convert it using a format string (or regex). The format string could be any format. ...

Categorized results – jQuery autocomplete plugin

I m looking for an autocomplete plugin that makes it easy to categorize search results. If that s unclear, take a look at Apple.com s search bar (top right). I know that script.aculo.us autocomplete ...

Limiting IntelliJ IDEA import suggestions on completion

When I type the name of a class which will need to be imported, IntelliJ lovingly pops up with a list of suggestions. However, most of the time those suggestions are things I d never want to import, ...

热门标签