diff options
| author | Ryan Cumming <etaoins@gmail.com> | 2019-06-30 10:49:07 +1000 |
|---|---|---|
| committer | Ryan Cumming <etaoins@gmail.com> | 2019-06-30 11:12:56 +1000 |
| commit | 8f726b7db65d3d9527cdb2fb682c195ad1446dbf (patch) | |
| tree | 82e44d62f3742c625b47a1cfb30e22573604c9fd /editors/code/src/test/utils | |
| parent | 27df89f47d5f0a6e8e62d517d98dda854efabc34 (diff) | |
| download | rust-8f726b7db65d3d9527cdb2fb682c195ad1446dbf.tar.gz rust-8f726b7db65d3d9527cdb2fb682c195ad1446dbf.zip | |
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/test/utils')
| -rw-r--r-- | editors/code/src/test/utils/diagnotics/rust.test.ts | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/editors/code/src/test/utils/diagnotics/rust.test.ts b/editors/code/src/test/utils/diagnotics/rust.test.ts index b555a481986..7fb003fe212 100644 --- a/editors/code/src/test/utils/diagnotics/rust.test.ts +++ b/editors/code/src/test/utils/diagnotics/rust.test.ts @@ -108,7 +108,10 @@ describe('mapRustDiagnosticToVsCode', () => { ); assert.strictEqual( diagnostic.message, - 'this function takes 2 parameters but 3 parameters were supplied' + [ + 'this function takes 2 parameters but 3 parameters were supplied', + 'expected 2 parameters' + ].join('\n') ); assert.strictEqual(diagnostic.code, 'E0061'); assert.strictEqual(diagnostic.source, 'rustc'); @@ -170,4 +173,28 @@ describe('mapRustDiagnosticToVsCode', () => { SuggestionApplicability.Unspecified ); }); + + it('should map a mismatched type error', () => { + const { diagnostic, suggestedFixes } = mapFixtureToVsCode( + 'error/E0308' + ); + + assert.strictEqual( + diagnostic.severity, + vscode.DiagnosticSeverity.Error + ); + assert.strictEqual( + diagnostic.message, + ['mismatched types', 'expected usize, found u32'].join('\n') + ); + assert.strictEqual(diagnostic.code, 'E0308'); + assert.strictEqual(diagnostic.source, 'rustc'); + assert.strictEqual(diagnostic.tags, undefined); + + // No related information + assert.deepStrictEqual(diagnostic.relatedInformation, []); + + // There are no suggested fixes + assert.strictEqual(suggestedFixes.length, 0); + }); }); |
