visual-studio-code - 在 vscode 中带有参数的 RUST cargo 运行任务

标签 visual-studio-code rust-cargo

有没有办法为作为 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/

相关文章:

ecmascript-6 - 我如何在 Visual Studio Code 中编写 ECMAScript 6?

visual-studio-code - 如何在 visual studio 代码中集成 git bash

visual-studio-code - 是否可以在编辑器右侧添加新菜单栏 - VSCode 扩展?

visual-studio-code - 是否可以始终在我的服务器上运行 remote-ssh 和 Live Share?

rust - 运行 "ld: library not found for -liconv"时应该如何解决 "cargo build"错误?

python - 为什么 python Visual Studio 代码中没有显示 pylint 的错误曲线?

dependencies - Cargo 无法下载 nom v0.5.0

gcc - 使用 Cargo 构建时找不到 `lcrypto` 或 `lssl`

rust - 如何修复 "use of extern prelude names introduced with ` extern crate` 项目不稳定”

rust - 如何将 Rust 位标志条目转换为 int