From 8f726b7db65d3d9527cdb2fb682c195ad1446dbf Mon Sep 17 00:00:00 2001 From: Ryan Cumming Date: Sun, 30 Jun 2019 10:49:07 +1000 Subject: Include primary span label in VS Code diagnostics In most cases the primary label span repeats information found elsewhere in the diagnostic. For example, with E0061: ``` { "message": "this function takes 2 parameters but 3 parameters were supplied", "spans": [{"label": "expected 2 parameters"}] } ``` However, with some mismatched type errors (E0308) the expected type only appears in the primary span's label, e.g.: ``` { "message": "mismatched types", "spans": [{"label": "expected usize, found u32"}] } ``` I initially added the primary span label to the message unconditionally. However, for most error types the child diagnostics repeat the primary span label with more detail. `rustc` also renders the duplicate text but because the span label and child diagnostics appear in visually distinct places it's not as confusing. This takes a heuristic approach where it will only add the primary span label if there are no child message lines. --- editors/code/src/utils/diagnostics/rust.ts | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'editors/code/src/utils/diagnostics/rust.ts') diff --git a/editors/code/src/utils/diagnostics/rust.ts b/editors/code/src/utils/diagnostics/rust.ts index d16576eb1..c07be4559 100644 --- a/editors/code/src/utils/diagnostics/rust.ts +++ b/editors/code/src/utils/diagnostics/rust.ts @@ -182,6 +182,7 @@ export function mapRustDiagnosticToVsCode( const secondarySpans = rd.spans.filter(s => !s.is_primary); const severity = mapLevelToSeverity(rd.level); + let primarySpanLabel = primarySpan.label; const vd = new vscode.Diagnostic(location.range, rd.message, severity); @@ -220,9 +221,17 @@ export function mapRustDiagnosticToVsCode( } if (messageLine) { vd.message += `\n${messageLine}`; + + // These secondary messages usually duplicate the content of the + // primary span label. + primarySpanLabel = undefined; } } + if (primarySpanLabel) { + vd.message += `\n${primarySpanLabel}`; + } + if (isUnusedOrUnnecessary(rd)) { vd.tags = [vscode.DiagnosticTag.Unnecessary]; } -- cgit v1.2.3