Rust Analyzer Vscode



Hello there!

Sublime Text 4 really close to release. Currently, I’m already using it as the main text editor.
You can check their changelog here click.

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.

Vscode
  • Developing in Rust using Visual Studio Code. Two of the best features when using an IDE are auto completing and debugging. Fortunately, we can have both with VSCode. Go to rust website and follow the install procedure Then use nightly channel to get the latest version of the toolchain.
  • VSCode Extensions. If you’re on MacOS, Linux or Windows then CodeLLDB. Windows users can also use the C/C Extension instead if they prefer but for the benefit of this, we will choose CodeLLDB. Regardless of which OS you use I recommend getting Rust Analyzer (RA). It has excellent IDE support for Rust and is being actively developed. If you’ve heard of RLS then Rust Analyzer is a replacement for that (often dubbed RLS.

Rust-analyzer Vs Rls Vscode

Download ST4 on top of ST3 you can here (It’s version 4070):
windows
linux deb
linux-sources
mac-os
I not really fan of vscode, which is written in js and launch time, traverse, animations. All is very slow (subjectively).
ST3 always was much faster and honestly, more minimal, what is also important for me (you even haven’t package manager when installing it).
After, when I installed the 4070 version it just skyrockets faster yay!.

Okay okay, let’s go-to Rust awesome integration.

Analyzer

Okay, here we installed gnu support for windows (msvc just much more aggressive and it will cut a lot of variables even in debug mode), added nightly toolchain, made it default and installed src code for it.

Vs Code Rust Analyzer

Now we need one more step - rust-analyzer

Rust Analyzer Vscode

Now the environment is ready. Let’s go to sublime text.

Install packages:

  1. LSP - auto suggestions, go to definition (uses rust analyzer behind)
  2. Debugger - full debugging experiece (via lldb)
  3. RustFmt - quick format or format on save
  4. Rust Enhanced - syntax highlighting, test, bench and build support

Okay, with LSP everything is simple: ctrl + shift + p -> Enable Language server globally -> rust-analyzer.It should write in the bottom left (where is the status bar) that rust analyzer initialized and wait for ~40 sec.
After you can press Ctrl + Shift + M and see all warnings, errors (even from clippy, which is configurable) and jump at them.
With Debugger, you need to create .sublime-project (better save this file in the root of your directory because it has variables for relative path handling). After, you can tap on Debugger and press Open. Install Adapters -> vscode-lldb (exactly the same plugin, which is using in vscode). When it finishes the install, you have full debugger support. But I wanted more. I want to enter std library sources. For some reason it’s not handled automatically (check this).First, start the debugger and try to step inside std function or macros (like println!()). You will receive assembly and line kinda this /rustc/f509b26a7730d721ef87423a72b3fdf8724b4afa. This is path to your rust source code, but, you know, it’s a bit wrong. You need to find real source code path, it will look kinda this C:/Users/krupi/.rustup/toolchains/nightly-x86_64-pc-windows-gnu/lib/rustlib/src/rust. Just remap weird hashed path to correct one in your .sublime-project and that it.
Full sublime project source:

Rust-analyzerRust

Add this file to .gitignore and you can separate debug configurations per pc or add more sourceMaps into your json array.Now you can jump left and right to your variables, system functions, macroses, build from ST3, test, run benchmarks, format code, debug and basically everything that you need in development.
Just check showcase below:

Vscode Rust-analyzer Failed To Discover Workspace

Hope it helps someone, see you next time.As always, if you have found any mistakes or have some remarks, waiting for you in the comments :)

Debug Rust In Vscode

P.S.Don’t forget to remap keys in key preferences to adopt if for yourself:

Rust Analyzer Rls

Provides support for rust-analyzer: novel LSP server for the Rust programming language.

Note the extension may cause conflicts with the official Rust extension. It is recommended to disable the Rust extension when using the rust-analyzer extension.

Note the project is in alpha status: it is already useful in practice, but can't be considered stable.

Sponsor

Work on rust-analyzer is sponsored by

If you want to sponsor:

Features

  • code completion, imports insertion
  • go to definition, implementation, type definition
  • find all references, workspace symbol search, rename
  • a lot of assist(code actions)
  • apply suggestions from errors
  • ... and many more, checkout the manual to see them all

Quick start

  1. Install rustup
  2. Install the rust-analyzer extension

Configuration

This extension provides configurations through VSCode's configuration settings. All the configurations are under rust-analyzer.*.

See https://rust-analyzer.github.io/manual.html#vs-code-2 for more information on VSCode specific configurations.

Communication

For usage and troubleshooting requests, please use 'IDEs and Editors' category of the Rust forum:

Documentation

See https://rust-analyzer.github.io/ for more information.