-
-
Save deadalusai/9e13e36d61ec7fb72148 to your computer and use it in GitHub Desktop.
/* | |
Before using this tasks.json you may like to consider trying one of the following VS Code extensions: | |
rust-analyzer | |
Marketplace: https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer | |
Source: https://github.com/rust-analyzer/rust-analyzer | |
rls | |
Marketplace: https://marketplace.visualstudio.com/items?itemName=rust-lang.rust | |
Source: https://github.com/rust-lang/rls-vscode | |
*/ | |
// Available variables which can be used inside of strings. | |
// ${workspaceRoot}: the root folder of the team | |
// ${file}: the current opened file | |
// ${fileBasename}: the current opened file's basename | |
// ${fileDirname}: the current opened file's dirname | |
// ${fileExtname}: the current opened file's extension | |
// ${cwd}: the current working directory of the spawned process | |
{ | |
"version": "2.0.0", | |
"tasks": [ | |
{ | |
"label": "build", | |
"args": ["build", "-v"], | |
"command": "cargo", | |
"group": "build", | |
"problemMatcher": [ | |
{ | |
"owner": "rust", | |
"fileLocation": ["relative", "${workspaceRoot}"], | |
"pattern": { | |
"regexp": "^(.*):(\\d+):(\\d+):\\s+(\\d+):(\\d+)\\s+(warning|error):\\s+(.*)$", | |
"file": 1, | |
"line": 2, | |
"column": 3, | |
"endLine": 4, | |
"endColumn": 5, | |
"severity": 6, | |
"message": 7 | |
} | |
} | |
] | |
}, | |
{ | |
"label": "clean", | |
"args": ["clean"], | |
"command": "cargo", | |
"presentation": { | |
"reveal": "always" | |
} | |
}, | |
{ | |
"label": "run", | |
"args": ["run", "-v"], | |
"command": "cargo", | |
"presentation": { | |
"reveal": "always" | |
}, | |
"group": { | |
"kind": "build", | |
"isDefault": true | |
}, | |
"problemMatcher": [ | |
{ | |
"owner": "rust", | |
"fileLocation": ["relative", "${workspaceRoot}"], | |
"pattern": { | |
"regexp": "^(.*):(\\d+):(\\d+):\\s+(\\d+):(\\d+)\\s+(warning|error):\\s+(.*)$", | |
"file": 1, | |
"line": 2, | |
"column": 3, | |
"endLine": 4, | |
"endColumn": 5, | |
"severity": 6, | |
"message": 7 | |
} | |
} | |
] | |
}, | |
{ | |
"label": "test", | |
"args": ["test"], | |
"command": "cargo", | |
"presentation": { | |
"reveal": "always" | |
}, | |
"group": { | |
"kind": "z", | |
"isDefault": false | |
}, | |
"problemMatcher": [ | |
{ | |
"owner": "rust", | |
"fileLocation": ["relative", "${workspaceRoot}"], | |
"pattern": { | |
"regexp": "^(.*):(\\d+):(\\d+):\\s+(\\d+):(\\d+)\\s+(warning|error):\\s+(.*)$", | |
"file": 1, | |
"line": 2, | |
"column": 3, | |
"endLine": 4, | |
"endColumn": 5, | |
"severity": 6, | |
"message": 7 | |
} | |
}, | |
{ | |
"owner": "rust", | |
"fileLocation": ["relative", "${workspaceRoot}"], | |
"severity": "error", | |
"pattern": { | |
"regexp": "^.*panicked\\s+at\\s+'(.*)',\\s+(.*):(\\d+)$", | |
"message": 1, | |
"file": 2, | |
"line": 3 | |
} | |
} | |
] | |
}, | |
{ | |
"label": "bench", | |
"args": ["bench"], | |
"command": "cargo", | |
"presentation": { | |
"reveal": "always" | |
}, | |
"group": "test", | |
"problemMatcher": [ | |
{ | |
"owner": "rust", | |
"fileLocation": ["relative", "${workspaceRoot}"], | |
"pattern": { | |
"regexp": "^(.*):(\\d+):(\\d+):\\s+(\\d+):(\\d+)\\s+(warning|error):\\s+(.*)$", | |
"file": 1, | |
"line": 2, | |
"column": 3, | |
"endLine": 4, | |
"endColumn": 5, | |
"severity": 6, | |
"message": 7 | |
} | |
}, | |
{ | |
"owner": "rust", | |
"fileLocation": ["relative", "${workspaceRoot}"], | |
"severity": "error", | |
"pattern": { | |
"regexp": "^.*panicked\\s+at\\s+'(.*)',\\s+(.*):(\\d+)$", | |
"message": 1, | |
"file": 2, | |
"line": 3 | |
} | |
} | |
] | |
} | |
] | |
} |
Thanks for the new syntax @mbartelsm - I've updated the Gist with your suggestions.
If you haven't already, I recommend checking out the rust language server-based VS Code extension:
https://marketplace.visualstudio.com/items?itemName=rust-lang.rust
It's replaced this tasks.json for me entirely.
@deadalusai How so? I have those extensions installed (rls, rust-language-server and code-lldb) and Ctrl+Shift+B still asks me to define a tasks.json definition for cargo build et al :_/
@brainstorm On my machine after creating a new rust project and opening it in VS Code:
> cargo new footest
> code footest
Hitting Ctrl+Shift+B
shows the following menu:
Just hitting Enter starts the build.
Clicking on the cog icon in that menu ejects a tasks.json
file which you can then customize and commit to source control.
Edit: here is the README - https://github.com/rust-lang/rls-vscode#tasks
Might be an OSX vs Windows difference, though that seems unlikely. I'd start checking that everything is up to date perhaps. This is the only VS Code extension I have installed:
https://marketplace.visualstudio.com/items?itemName=rust-lang.rust
No worries, a year later it works :P
👍
Just to move the goalposts again, apparently the rust-analyzer project now provides a better experience.
https://marketplace.visualstudio.com/items?itemName=matklad.rust-analyzer
@deadalusai This work ok with the rust-analyzer
plugin?
@wonbyte as I mentioned, I'd suggest using rust-analyzer
instead of this tasks.json
.
i see got it!
The updated version doesn't work properly (only build is available). Try this one
The default build task here is
cargo run
but you can switch it withcargo build