有没有办法为作为 VS CODE 任务运行的 RUST cargo 命令指定参数?
或者我应该将其作为 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}"
]
}
]
}
关于visual-studio-code - 在 vscode 中带有参数的 RUST cargo 运行任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60380955/