Cargo Lens for Rust (VS Code Extension)
Adds CodeLens helpers above comments in Rust (.rs) files that contain cargo commands. When the extension finds cargo in a comment it will:
- If the
cargo command appears inside single backticks (...), it will take the full content inside the backticks as the command.
- Otherwise it will try to intelligently grab the cargo command text near
cargo (up to punctuation like . ; ! ? or end of comment).
- Place multiple CodeLens actions above the comment:
- "Run: " — opens an integrated terminal and runs the command (focused).
- "Run in background: " — runs the command in a terminal but does NOT focus the terminal (background).
- "Copy: " — copies the command text to the clipboard.
Install / build
- npm install
- npm run compile
- In VS Code press F5 to launch an Extension Development Host for testing.
Activation
- The extension activates for Rust files (language id
rust).
Notes & Limitations
- Heuristic parsing — it tries to be helpful but might not be perfect for every comment style.
- Multi-command comments may produce multiple lenses.
- Background run creates a terminal and does not focus it; the terminal is still visible in the Terminal panel if the user opens it.
- You can modify the heuristics in extractCargoCommandsFromComment to fine-tune command extraction.
Ideas for further improvements:
- Add settings to choose working directory (file folder vs workspace root).
- Allow configuring whether the background command should show the terminal panel or be fully hidden.
- Add a "Run with args..." input box.
| |