Skip to content

Instantly share code, notes, and snippets.

@vilicvane
Last active April 13, 2020 22:56
Show Gist options
  • Save vilicvane/f756ccfdb91b004e7a70 to your computer and use it in GitHub Desktop.
Save vilicvane/f756ccfdb91b004e7a70 to your computer and use it in GitHub Desktop.
Show rust build errors in Visual Studio Code.
var ChildProcess = require('child_process');
var task = process.argv[2];
var cargo = ChildProcess.exec('cargo ' + task);
cargo.stdout.on('data', function (data) {
process.stdout.write(data);
});
cargo.stderr.on('data', function (data) {
var lines = data
.split(/\n\s*/)
.map(function (line, index) {
if (!line || (index && /^[^:]+\.rs:/.test(line))) {
return '\n' + line;
} else {
return line;
}
});
data = lines.join(' ');
process.stderr.write(data);
});
cargo.on('error', function (error) {
process.exit(1);
});
{
"version": "0.1.0",
"command": "node",
"showOutput": "silent",
"tasks": [
{
"taskName": "build",
"isBuildCommand": true,
"args": [
".settings/cargo-shell.js",
"build"
],
"problemMatcher": {
"fileLocation": ["relative", "${cwd}"],
"pattern": {
"regexp": "^([^:]*\\.rs):(\\d+):(\\d+): (\\d+):(\\d+) (error|warning|info): (.+?)(?:\\s*\\[([^\\]]+)\\]\\s*)?$",
"file": 1,
"line": 2,
"column": 3,
"endLine": 4,
"endColumn": 5,
"severity": 6,
"message": 7,
"code": 8
}
}
},
{
"taskName": "test",
"isTestCommand": true,
"args": [
".settings/cargo-shell.js",
"run"
],
"problemMatcher": {
"fileLocation": ["relative", "${cwd}"],
"pattern": {
"regexp": "^([^:]*\\.rs):(\\d+):(\\d+): (\\d+):(\\d+) (error|warning|info): (.+?)(?:\\s*\\[([^\\]]+)\\]\\s*)?$",
"file": 1,
"line": 2,
"column": 3,
"endLine": 4,
"endColumn": 5,
"severity": 6,
"message": 7,
"code": 8
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment