Cargo Scripts for VS Code
A Visual Studio Code extension that helps Rust developers run Cargo scripts directly from the sidebar - similar to npm scripts in package.json.
✨ Features
- 🚀 Auto-detects
.cargo/config.toml and Cargo.toml configurations
- ⚡ One-click script execution via sidebar
- 🐛 Debug cargo scripts via CodeLLDB
- 🔍 Auto-reload on config changes
🛠 Installation
- Open VS Code Extensions Marketplace
- Search for
Cargo Scripts or taiyuuki.vscode-cargo-scripts
- Click Install
- Reload the editor
Or install via command line:
code --install-extension taiyuuki.vscode-cargo-scripts
🚦 Usage
Define your scripts in either .cargo/config.toml or Cargo.toml.
[alias] in .cargo/config.toml (Recommended)
Refer to The Cargo Book for details about the [alias] section.
Example configuration:
[alias]
r = "run --release"
b = "build --release"
t = ["test", "--", "--nocapture"]
The scripts will appear in the CARGO SCRIPTS sidebar. Click the ▶️ icon next to any script to execute it.
Cargo.toml Configuration
Add a [package.metadata.scripts] or [workspace.metadata.scripts] section (for workspace projects).
Important notes:
- Commands must be full command-line strings (include cargo prefix)
- Workspace configuration takes precedence over package configuration
Example:
[package.metadata.scripts]
run = "cargo run"
build = "cargo build --release"
test = "cargo test -- --nocapture"
# For workspace projects
[workspace.metadata.scripts]
lint = "cargo clippy --all-targets -- -D warnings"
🐛 Debugging
Click the debug icon next to any script in the sidebar (or the Debug CodeLens above the script definition) to start a debug session.
Requirements:
- The script must be a
cargo command that launches a target (run, test, bench, ...). Non-cargo commands and subcommands such as check, clippy or watch cannot be debugged.
- The CodeLLDB extension must be installed — the debug actions are hidden until it is.
For test and bench scripts, targets are built with --no-run first, and the chosen test executable is launched directly — if several test targets exist, you will be asked which one to debug.