如何使VS代码构建和运行Rust程序?

XAM*_*cky 7 rust visual-studio-code

我一直在使用VS Code,我想知道如何构建一个task.json具有这些命令的文件.cargo build,cargo run [ARGS] cargo run --release -- [ARGS]

我试着做一个与文件task.json.我一直在No such subcommand犯错.

样品:

{
"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"
}]
}
Run Code Online (Sandbox Code Playgroud)

小智 4

这些答案可能已经过时了,这是我的tasks.json,它实现了cargo run、cargo build和cargo命令来运行当前打开的示例......

关键是指定问题匹配器,这样您就可以点击错误:

{
    // 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"
            ]
        },
    ]
}
Run Code Online (Sandbox Code Playgroud)