aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/utils/diagnostics
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-06-30 10:54:47 +0100
committerbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-06-30 10:54:47 +0100
commitfb2534f30089ddd796dbf52c7bb639efe5d10a3e (patch)
treeb08792995d3aafe3f203372984722714c6954d2e /editors/code/src/utils/diagnostics
parent950da94c3aaebb783d20be2552b6c1b77e92c7a0 (diff)
parent8f726b7db65d3d9527cdb2fb682c195ad1446dbf (diff)
Merge #1459
1459: Include primary span label in VS Code diagnostics r=matklad a=etaoins In most cases the primary label span repeats information found elsewhere in the diagnostic. For example, with E0061: ```json { "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.: ```json { "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. For most error types the child messages repeat the primary span label with more detail. Co-authored-by: Ryan Cumming <[email protected]>
Diffstat (limited to 'editors/code/src/utils/diagnostics')
-rw-r--r--editors/code/src/utils/diagnostics/rust.ts9
1 files changed, 9 insertions, 0 deletions
diff --git a/editors/code/src/utils/diagnostics/rust.ts b/editors/code/src/utils/diagnostics/rust.ts
index 5e2d6b6ff..bfb494a3a 100644
--- a/editors/code/src/utils/diagnostics/rust.ts
+++ b/editors/code/src/utils/diagnostics/rust.ts
@@ -183,6 +183,7 @@ export function mapRustDiagnosticToVsCode(
183 const secondarySpans = rd.spans.filter(s => !s.is_primary); 183 const secondarySpans = rd.spans.filter(s => !s.is_primary);
184 184
185 const severity = mapLevelToSeverity(rd.level); 185 const severity = mapLevelToSeverity(rd.level);
186 let primarySpanLabel = primarySpan.label;
186 187
187 const vd = new vscode.Diagnostic(location.range, rd.message, severity); 188 const vd = new vscode.Diagnostic(location.range, rd.message, severity);
188 189
@@ -221,9 +222,17 @@ export function mapRustDiagnosticToVsCode(
221 } 222 }
222 if (messageLine) { 223 if (messageLine) {
223 vd.message += `\n${messageLine}`; 224 vd.message += `\n${messageLine}`;
225
226 // These secondary messages usually duplicate the content of the
227 // primary span label.
228 primarySpanLabel = undefined;
224 } 229 }
225 } 230 }
226 231
232 if (primarySpanLabel) {
233 vd.message += `\n${primarySpanLabel}`;
234 }
235
227 if (isUnusedOrUnnecessary(rd)) { 236 if (isUnusedOrUnnecessary(rd)) {
228 vd.tags = [vscode.DiagnosticTag.Unnecessary]; 237 vd.tags = [vscode.DiagnosticTag.Unnecessary];
229 } 238 }