Dr.*_*YSG 8 rust-cargo visual-studio-code
有没有办法为作为 VS CODE 任务运行的 RUST 货物命令指定参数?或者我应该将其作为 NPM 脚本尝试?(当然,这是 RUST,所以我使用 CARGO 和 npm,创建 package.json 会很奇怪)。
构建任务工作正常:
"version": "2.0.0",
"tasks": [
{
"type": "cargo",
"subcommand": "build",
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
Run Code Online (Sandbox Code Playgroud)
但我不知道把论点放在哪里,因为我希望它是
$cargo run [filename]
Run Code Online (Sandbox Code Playgroud)
{
"type": "cargo",
"subcommand": "run",
"problemMatcher": [
"$rustc"
]
}
Run Code Online (Sandbox Code Playgroud)
绝对有,该args选项允许您向任务传递附加参数,并且您可以使用各种${template}参数来传递当前打开的文件等内容。
还值得指出的是,命令的类型可能应该是shell,并cargo指定为命令本身。
对于您的用例,您可以考虑使用以下命令(执行cargo run $currentFile)。
{
"version": "2.0.0",
"tasks": [
{
"label": "run",
"type": "shell",
"problemMatcher": [
"$rustc"
],
"command": "cargo",
"args": [
"run",
"${file}"
]
}
]
}
Run Code Online (Sandbox Code Playgroud)