From a8a1bc4b15b75e5702cb1ce1d4c5ab3153dbe3c9 Mon Sep 17 00:00:00 2001 From: Ryan Cumming Date: Thu, 27 Jun 2019 08:47:36 +1000 Subject: Extract lint scopes from `cargo watch` Currently all of our VS Code diagnostics are given the source of `rustc`. However, if you have something like `cargo-watch.command` set to `clippy` it will also watch for Clippy lints. The `rustc` source is a bit misleading in that case. Fortunately, Rust's tool lints (RFC 2103) line up perfectly with VS Code's concept of `source`. This checks for lints scoped to a given tool and then splits them in to a `source` and tool-specific `code`. --- editors/code/src/utils/rust_diagnostics.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'editors/code/src/utils') diff --git a/editors/code/src/utils/rust_diagnostics.ts b/editors/code/src/utils/rust_diagnostics.ts index ed049c95e..3c524cb37 100644 --- a/editors/code/src/utils/rust_diagnostics.ts +++ b/editors/code/src/utils/rust_diagnostics.ts @@ -187,8 +187,18 @@ export function mapRustDiagnosticToVsCode( const vd = new vscode.Diagnostic(location.range, rd.message, severity); - vd.source = 'rustc'; - vd.code = rd.code ? rd.code.code : undefined; + let source = 'rustc'; + let code = rd.code && rd.code.code; + if (code) { + // See if this is an RFC #2103 scoped lint (e.g. from Clippy) + const scopedCode = code.split('::'); + if (scopedCode.length === 2) { + [source, code] = scopedCode; + } + } + + vd.source = source; + vd.code = code; vd.relatedInformation = []; for (const secondarySpan of secondarySpans) { -- cgit v1.2.3