Rust
Open a Cargo project and you get completion, navigation, inspections and formatting from
rust-analyzer, run and test configurations from Cargo.toml, and a debugger through lldb-dap.
Rust support is Works.
Before you start
Section titled “Before you start”-
Cargo and rustup, from rustup.rs.
-
rust-analyzer for the toolchain the project uses:
-
lldb-dap for debugging. On macOS it comes with Xcode or its command line tools; Ferris IDEA also finds it through
xcrun. On Linux it is part of LLDB (lldb-dap, orlldb-dap-18and similar, or under/usr/lib/llvm-N/bin). -
Developer Mode on macOS for debugging native programs:
sudo DevToolsSecurity -enable.
The toolchain rust-analyzer runs under
Section titled “The toolchain rust-analyzer runs under”~/.cargo/bin/rust-analyzer is a rustup proxy: it starts the rust-analyzer of the toolchain that
applies to the project folder, which a rust-toolchain.toml or a rustup override can choose.
Ferris IDEA asks rustup which toolchain that is before it starts the server, without letting
rustup install anything. If that toolchain lacks the component, the message names it and the
exact command, for example:
rustup component add rust-analyzer --toolchain nightly-aarch64-apple-darwinWhat you get
Section titled “What you get”- Completion, parameter info, quick documentation, go to declaration and implementation, find usages, call hierarchy, rename across files, inspections and quick fixes from rust-analyzer.
- Reformat Code (⌥⌘L) formats with rustfmt through rust-analyzer. A selection is formatted as part of the whole file.
- Not available: the type hierarchy, because rust-analyzer does not offer one.
In a project you have not trusted, rust-analyzer starts without build scripts, proc macros and the check on save, so code generated by macros is not understood until you trust the project.
Run and test
Section titled “Run and test”-
Open the project. The run widget’s list shows cargo build and cargo test under “Detected from build files”. In a workspace each member that is not at the root gets its folder in brackets.
-
In
src/main.rsthe gutter shows ▶ next tofn main, and next to every#[test]and#[tokio::test]function. -
Run › Run Current File (⌃⇧R) picks what fits the caret:
Caret in Command src/main.rscargo run --bin <package>src/bin/name.rsorsrc/bin/name/main.rscargo run --bin nameexamples/name.rscargo run --example namea test function cargo test path::name -- --exacta file with tests and no maincargo test -
Test runs fill the result tree from Cargo’s own test output; see Run tests.
To keep a command with your own arguments, copy a detected configuration into run.toml
(Run configurations).
- Set a breakpoint with a click on the line number, or ⌘F8.
- Run › Debug Current File (⌃⇧D) on
src/main.rs. Ferris IDEA builds withcargo build, then starts the built program under lldb-dap. - The program stops at the breakpoint; step, inspect and evaluate as described in Debug a program.
Only the plain cargo build is followed: --release, -p, --target and similar options of a
cargo run configuration are not, so the debugger starts the debug build of the default target.
When it does not work
Section titled “When it does not work”- “rust-analyzer is a rustup proxy without the component in the toolchain …”: run the command in the message; it names the toolchain the project folder uses.
- “Cannot debug: lldb-dap is not installed”: install Xcode’s command line tools (macOS) or LLDB (Linux).
- “Cannot debug: this Mac needs Developer Mode”: run
sudo DevToolsSecurity -enableonce. - Macros are not expanded: the project is in safe mode; trust it.
Shortcuts
Section titled “Shortcuts”| Action | Shortcut |
|---|---|
| Code › Reformat Code | ⌥⌘LCtrlAltL |
| Navigate › Implementation(s) | ⌥⌘BCtrlAltB |
| Run › Debug Current File | ⌃⇧Dno shortcut |
| Run › Run Current File | ⌃⇧RCtrlShiftF10 |
| Run › Toggle Line Breakpoint | ⌘F8CtrlF8 |
For agents
Section titled “For agents”debug_startStart a debug session: native programs with lldb-dap, Go with Delve (go_testfor tests), Python with debugpy, Node.js/TypeScript scripts or annpm_scriptwith js-debug, or a Kotlinmain_class.format_fileFormat a workspace file (or arange) as Reformat Code does.language_serversLanguage servers per language: the candidates Ferris IDEA can use, which one is selected on this machine, why the others are unusable (missing, not executable, rustup proxy without the component in the toolchain the workspace folder uses) and how to install them.run_commandRun one program with arguments in the workspace (no shell).run_markersThe run markers (gutter ▶) of a file with 1-based line and the run configuration each starts: Java/Kotlinmainand JUnit tests (single method via Maven or Gradle), Vitest/Jestdescribe/it/test, pytest, Go and Rust tests, and themainof Go programs, Rust binaries and examples, and Python scripts (kindmain).
No tool matches. Try fewer words, or .