I've been using VS Code, and I was wondering how to build a task.json
file that will have these commands. cargo build
, cargo run [ARGS]
cargo run --release -- [ARGS]
I've tried making one with the documentation on task.json
. I kept getting No such subcommand
errors.
Sample:
{
"version": "0.1.0",
// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
"command": "cargo",
// The command is a shell script
"isBuildCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
"tasks": [{
"taskName": "run test",
"version": "0.1.0",
"command": "run -- --exclude-dir=node_modules C:/Users/Aaron/Documents/Github/",
"isShellCommand": true,
"showOutput": "always"
},
{
"taskName": "run",
"version": "0.1.0",
"args": [ "--"
, "--exclude-dir=node_modules"
, "C:/Users/Aaron/Documents/Github/"
]
"isShellCommand": true,
"showOutput": "always"
}]
}
Possibly these answers are out of date, here is my tasks.json, which implements cargo run, cargo build and a cargo command to run the currently open example...
A key thing is to specify the problem matcher, so you can click through errors:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "cargo run example",
"type": "shell",
"command": "cargo run --example ${fileBasenameNoExtension}",
"problemMatcher": [
"$rustc"
]
},
{
"label": "cargo run",
"type": "shell",
"command": "cargo run",
"problemMatcher": [
"$rustc"
]
},
{
"label": "cargo build",
"type": "shell",
"command": "cargo build",
"problemMatcher": [
"$rustc"
]
},
]
}
The command property is only supported at the top level. In addition, arguments have to be passed via the args property. If they are put into the command, the command is treated as a command with whitespaces in its name. An example of the run task would look like this:
{
"version": "0.1.0",
"command": "cargo",
"isShellCommand": true, // Only needed if cargo is a .cmd file
"tasks": [
{
"taskName": "run",
"args": [
"--release"
// More args
],
"showOutput": "always"
}
]
}
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