Is there a way to specify arguments to a RUST cargo command running as VS CODE task? Or should I be trying this as an NPM script? (of course, this is RUST, so I am using CARGO and npm, creating a package.json would be odd).
The Build task works fine:
"version": "2.0.0",
"tasks": [
{
"type": "cargo",
"subcommand": "build",
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
But I have no idea where to put the arguments since I want it to be
$cargo run [filename]
{
"type": "cargo",
"subcommand": "run",
"problemMatcher": [
"$rustc"
]
}
Command line arguments In the Properties Pane, go to "Debugging", and in this pane is a line for "Command-line arguments." Add the values you would like to use on this line. They will be passed to the program via the argv array.
Cargo can be used to build your Rust project. Open a new VS Code integrated terminal (Ctrl+Shift+`) and type cargo build . You will now have target\debug folder with build output include an executable called hello_world.exe .
First, download and install Visual Studio Code for Windows. After you've installed VS Code, install the rust-analyzer extension. You can either install the rust-analyzer extension from the Visual Studio Marketplace, or you can open VS Code, and search for rust-analyzer in the extensions menu (Ctrl+Shift+X).
Visual Studio Code (VS Code) Visual Studio Code is an open source and free-for-use project created by Microsoft and available for macOS, Windows, and Linux. It supports a lot of major languages, including Rust. Currently, VS Code is one of the best code editors around and the most-used editor for Rust development.
There absolutely is, the args
option allows you to pass additional arguments to your tasks and you can use various ${template}
parameters to pass things like the currently opened file.
It's also worth calling out that the type of the command should probably be shell
, with cargo
being specified as the command itself.
For your use case, you may consider using the following (to execute cargo run $currentFile
).
{
"version": "2.0.0",
"tasks": [
{
"label": "run",
"type": "shell",
"problemMatcher": [
"$rustc"
],
"command": "cargo",
"args": [
"run",
"${file}"
]
}
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With