No Rust autocomplete in Visual Studio Code for external crates such as 'gtk-rs'
Although there could be many possible causes of a problem with the Rust extension in Visual Studio Code, the following steps should help anyone with issues of this kind:
Do not use the old extension "Rusty Code", since it's no longer maintained. Instead, you have two options:
- rust-analyzer provides by far the best Rust language support and is already part of the Rust organization. This is the recommended choice today.
- rust-lang.rust is an older extension developed by an official Rust team and is focused on Rust Language Server (RLS) integration. It is not as powerful.
- The kalitaalexey.vscode-rust extension was forked from Rusty Code to make it more stable, but that one too eventually lost maintenance.
When using RLS, you might need to build your project so that dependencies are downloaded and compiled locally, thus enabling the extension to retrieve additional information about them.
It's always worth making sure that the extension is up to date and properly configured. Update the extension, and check out the respective documentation for instructions on how to make it work.
Check the status bar. If something is wrong, it should tell you so. Open the extension task's output window for error messages. If something still isn't right, try reloading your window.
If there's still a problem after these steps, it might actually be a bug, which should be reported.
If you're just starting with Rust and VSCode, and want to enable autocomplete, this is what I did (Novemeber 2021):
- Install Rust extension in VSCode
- Open root folder of you existing Rust project(or create new) in VSCode (and select "trust workspace" if asked)
- Open src/main.rs, now in lower right corner VSCode will ask you to install some components, click yes and it will install both Rust Language Server and Rust Analyzer
- Autocomplete should now work with CTRL+SPACE
For me solution was to use Rust Analyzer extension https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer instead of rust-lang.rust https://marketplace.visualstudio.com/items?itemName=rust-lang.rust