rust-analyzer: Manually Reloading Workspace

rust-analyzer wasn’t picking up my Cargo.toml changes. Had to reload manually.

The Problem

Modified Cargo.toml to add a new dependency. rust-analyzer didn’t notice. LSP features (autocomplete, goto definition) didn’t work for the new crate.

Why It Happens

rust-analyzer doesn’t actively watch for file changes (open issue).

It loads the workspace once at startup. After that, you’re on your own.

The Solution

In Emacs with LSP mode:

M-x lsp-rust-analyzer-reload-workspace

rust-analyzer re-reads Cargo.toml and rebuilds its index.

For Other Editors

VS Code:

Vim/Neovim with coc-rust-analyzer:

:CocCommand rust-analyzer.reloadWorkspace

Generic LSP:

When to Reload

Reload after:

Basically, any change that affects project structure.

Alternative

Just restart your editor. Slower, but guaranteed to work.

But for quick iterations, manual reload is faster.