Skip to content

Instantly share code, notes, and snippets.

@deadalusai
Last active September 23, 2023 03:18
Show Gist options
  • Star 26 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save deadalusai/9e13e36d61ec7fb72148 to your computer and use it in GitHub Desktop.
Save deadalusai/9e13e36d61ec7fb72148 to your computer and use it in GitHub Desktop.
VS Code tasks.json for Rust/Cargo
/*
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
}
}
]
}
]
}
@brainstorm
Copy link

brainstorm commented Apr 28, 2020

Interesting. On my OSX machine Cmd+Pand then > Cargo: Build seems to do the right thing, collecting warnings/errors right. On the other hand, Cmd+Shift+B shows up this:

Skärmavbild 2020-04-28 kl  14 29 25

I am working on a remote (SSH plugin) VSCode project, for more context.

@deadalusai
Copy link
Author

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

@brainstorm
Copy link

No worries, a year later it works :P

@deadalusai
Copy link
Author

👍

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

@wonbyte
Copy link

wonbyte commented Jun 16, 2021

@deadalusai This work ok with the rust-analyzer plugin?

@deadalusai
Copy link
Author

@wonbyte as I mentioned, I'd suggest using rust-analyzer instead of this tasks.json.

@wonbyte
Copy link

wonbyte commented Jun 18, 2021

i see got it!

@epenabella
Copy link

use --manifest-path

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment