liveBook · Manning

Rust-analyzer

As explained in Code Like a Pro in Rust

rust-analyzer is a Rust language server providing IDE features such as analysis, navigation, and completion.

rust-analyzer provides Rust IDE features through editors that support the Language Server Protocol (LSP). Use it for code completion, import insertion, definition navigation, inline compiler errors, type and parameter inlay hints, and refactoring. section 3.2

To use it in VS Code:

  • Install the rust-src component with `rustup component add rust-src`, then install the rust-analyzer extension. section 3.6
  • Open a Rust project; the extension recognizes its Cargo.toml and loads the project. Run `code .` from the project directory to open it there. section 3.6
$ rustup component add rust-src

Command for installing the rust-src component before VS Code setup. section 3.6

For a context-aware rename in VS Code, select a symbol and press F2 or choose Rename Symbol. For broader changes, structural search-and-replace matches parsed expressions, types, paths, or items rather than raw text. It applies substitutions across the workspace by default and only accepts results that are syntactically valid. section 6.7.2

Replace a method call structurally

Use `$m.lock() => Mutex::lock(&$m)` to change matching Mutex method calls to the equivalent associated-function form. With `use std::sync::Mutex` in scope, the replacement can name `Mutex::lock` without writing its full path. section 6.7.2

Prefer symbol renaming or structural replacement over plain find-and-replace when a change depends on Rust syntax or name context. Other LSP-capable editors can also integrate rust-analyzer; IntelliJ Rust does not require a separate rust-analyzer extension. section 6.7.2 section 3.2

How Code Like a Pro in Rust covers it

How deep it goes
Works through VS Code setup and structural replacement, describing syntax-tree matching without detailing language-server internals.
Examples
Uses VS Code installation commands, F2 symbol renaming, and a Mutex method-call substitution.
What it assumes
Assumes a Rust project with Cargo.toml and shows the rustup and VS Code setup commands rather than teaching Rust syntax.
What you can do after
Apply it via a compatible editor to navigate Rust code and perform syntax-aware renames and workspace replacements.
How it connects
Connects rust-analyzer to LSP, VS Code, Cargo.toml, rustup, symbol renaming, and structural search-and-replace.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Code Like a Pro in Rust. The section links point to the parts of the book it draws on.