RUST cargo 运行 任务,参数在 vscode 中
RUST cargo run task with arguments in vscode
有没有办法将 RUST cargo 命令 运行 的参数指定为 VS CODE 任务?
或者我应该将其作为 NPM 脚本来尝试吗? (当然,这是 RUST,所以我使用 CARGO 和 npm,创建一个 package.json 会很奇怪)。
构建任务运行良好:
"version": "2.0.0",
"tasks": [
{
"type": "cargo",
"subcommand": "build",
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
但是我不知道把参数放在哪里,因为我想要它
$cargo run [filename]
{
"type": "cargo",
"subcommand": "run",
"problemMatcher": [
"$rustc"
]
}
绝对有,args
选项允许您将额外的参数传递给您的任务,您可以使用各种 ${template}
参数来传递诸如当前打开的文件之类的东西。
同样值得一提的是,命令的类型可能应该是 shell
,cargo
被指定为命令本身。
对于您的用例,您可以考虑使用以下内容(执行 cargo run $currentFile
)。
{
"version": "2.0.0",
"tasks": [
{
"label": "run",
"type": "shell",
"problemMatcher": [
"$rustc"
],
"command": "cargo",
"args": [
"run",
"${file}"
]
}
]
}
有没有办法将 RUST cargo 命令 运行 的参数指定为 VS CODE 任务? 或者我应该将其作为 NPM 脚本来尝试吗? (当然,这是 RUST,所以我使用 CARGO 和 npm,创建一个 package.json 会很奇怪)。
构建任务运行良好:
"version": "2.0.0",
"tasks": [
{
"type": "cargo",
"subcommand": "build",
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
但是我不知道把参数放在哪里,因为我想要它
$cargo run [filename]
{
"type": "cargo",
"subcommand": "run",
"problemMatcher": [
"$rustc"
]
}
绝对有,args
选项允许您将额外的参数传递给您的任务,您可以使用各种 ${template}
参数来传递诸如当前打开的文件之类的东西。
同样值得一提的是,命令的类型可能应该是 shell
,cargo
被指定为命令本身。
对于您的用例,您可以考虑使用以下内容(执行 cargo run $currentFile
)。
{
"version": "2.0.0",
"tasks": [
{
"label": "run",
"type": "shell",
"problemMatcher": [
"$rustc"
],
"command": "cargo",
"args": [
"run",
"${file}"
]
}
]
}