diff options
author | Ryan Cumming <[email protected]> | 2019-06-30 01:49:07 +0100 |
---|---|---|
committer | Ryan Cumming <[email protected]> | 2019-06-30 02:12:56 +0100 |
commit | 8f726b7db65d3d9527cdb2fb682c195ad1446dbf (patch) | |
tree | 82e44d62f3742c625b47a1cfb30e22573604c9fd /editors/code/src/utils | |
parent | 27df89f47d5f0a6e8e62d517d98dda854efabc34 (diff) |
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.
Diffstat (limited to 'editors/code/src/utils')
-rw-r--r-- | editors/code/src/utils/diagnostics/rust.ts | 9 |
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 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( | |||
182 | const secondarySpans = rd.spans.filter(s => !s.is_primary); | 182 | const secondarySpans = rd.spans.filter(s => !s.is_primary); |
183 | 183 | ||
184 | const severity = mapLevelToSeverity(rd.level); | 184 | const severity = mapLevelToSeverity(rd.level); |
185 | let primarySpanLabel = primarySpan.label; | ||
185 | 186 | ||
186 | const vd = new vscode.Diagnostic(location.range, rd.message, severity); | 187 | const vd = new vscode.Diagnostic(location.range, rd.message, severity); |
187 | 188 | ||
@@ -220,9 +221,17 @@ export function mapRustDiagnosticToVsCode( | |||
220 | } | 221 | } |
221 | if (messageLine) { | 222 | if (messageLine) { |
222 | vd.message += `\n${messageLine}`; | 223 | vd.message += `\n${messageLine}`; |
224 | |||
225 | // These secondary messages usually duplicate the content of the | ||
226 | // primary span label. | ||
227 | primarySpanLabel = undefined; | ||
223 | } | 228 | } |
224 | } | 229 | } |
225 | 230 | ||
231 | if (primarySpanLabel) { | ||
232 | vd.message += `\n${primarySpanLabel}`; | ||
233 | } | ||
234 | |||
226 | if (isUnusedOrUnnecessary(rd)) { | 235 | if (isUnusedOrUnnecessary(rd)) { |
227 | vd.tags = [vscode.DiagnosticTag.Unnecessary]; | 236 | vd.tags = [vscode.DiagnosticTag.Unnecessary]; |
228 | } | 237 | } |