Skip to content

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.

  • Cargo and rustup, from rustup.rs.

  • rust-analyzer for the toolchain the project uses:

    Terminal window
    rustup component add rust-analyzer

    The install command Ferris IDEA names in language_servers, version 1.6.0.

  • 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, or lldb-dap-18 and similar, or under /usr/lib/llvm-N/bin).

  • Developer Mode on macOS for debugging native programs: sudo DevToolsSecurity -enable.

~/.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-darwin
  • 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.

  1. 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.

  2. In src/main.rs the gutter shows ▶ next to fn main, and next to every #[test] and #[tokio::test] function.

  3. Run › Run Current File (⌃⇧R) picks what fits the caret:

    Caret in Command
    src/main.rs cargo run --bin <package>
    src/bin/name.rs or src/bin/name/main.rs cargo run --bin name
    examples/name.rs cargo run --example name
    a test function cargo test path::name -- --exact
    a file with tests and no main cargo test
  4. 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).

  1. Set a breakpoint with a click on the line number, or ⌘F8.
  2. Run › Debug Current File (⌃⇧D) on src/main.rs. Ferris IDEA builds with cargo build, then starts the built program under lldb-dap.
  3. 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.

  • “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 -enable once.
  • Macros are not expanded: the project is in safe mode; trust it.
Keyboard of
ActionShortcut
Code › Reformat Code⌥⌘LCtrlAltL
Navigate › Implementation(s)⌥⌘BCtrlAltB
Run › Debug Current File⌃⇧Dno shortcut
Run › Run Current File⌃⇧RCtrlShiftF10
Run › Toggle Line Breakpoint⌘F8CtrlF8

  • debug_startchangesdry run by defaultdebugtrusted-projectStart a debug session: native programs with lldb-dap, Go with Delve (go_test for tests), Python with debugpy, Node.js/TypeScript scripts or an npm_script with js-debug, or a Kotlin main_class.
  • format_filechangesdry run by defaultwritetrusted-projectFormat a workspace file (or a range) as Reformat Code does.
  • language_serversreadsLanguage 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_commandchangesdry run by defaultruntrusted-projectRun one program with arguments in the workspace (no shell).
  • run_markersreadsdry run by defaultThe run markers (gutter ▶) of a file with 1-based line and the run configuration each starts: Java/Kotlin main and JUnit tests (single method via Maven or Gradle), Vitest/Jest describe/it/test, pytest, Go and Rust tests, and the main of Go programs, Rust binaries and examples, and Python scripts (kind main).