diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-06-30 10:54:47 +0100 |
---|---|---|
committer | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-06-30 10:54:47 +0100 |
commit | fb2534f30089ddd796dbf52c7bb639efe5d10a3e (patch) | |
tree | b08792995d3aafe3f203372984722714c6954d2e /editors/code/src/test/utils/diagnotics | |
parent | 950da94c3aaebb783d20be2552b6c1b77e92c7a0 (diff) | |
parent | 8f726b7db65d3d9527cdb2fb682c195ad1446dbf (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/test/utils/diagnotics')
-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 b555a4819..7fb003fe2 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', () => { | |||
108 | ); | 108 | ); |
109 | assert.strictEqual( | 109 | assert.strictEqual( |
110 | diagnostic.message, | 110 | diagnostic.message, |
111 | 'this function takes 2 parameters but 3 parameters were supplied' | 111 | [ |
112 | 'this function takes 2 parameters but 3 parameters were supplied', | ||
113 | 'expected 2 parameters' | ||
114 | ].join('\n') | ||
112 | ); | 115 | ); |
113 | assert.strictEqual(diagnostic.code, 'E0061'); | 116 | assert.strictEqual(diagnostic.code, 'E0061'); |
114 | assert.strictEqual(diagnostic.source, 'rustc'); | 117 | assert.strictEqual(diagnostic.source, 'rustc'); |
@@ -170,4 +173,28 @@ describe('mapRustDiagnosticToVsCode', () => { | |||
170 | SuggestionApplicability.Unspecified | 173 | SuggestionApplicability.Unspecified |
171 | ); | 174 | ); |
172 | }); | 175 | }); |
176 | |||
177 | it('should map a mismatched type error', () => { | ||
178 | const { diagnostic, suggestedFixes } = mapFixtureToVsCode( | ||
179 | 'error/E0308' | ||
180 | ); | ||
181 | |||
182 | assert.strictEqual( | ||
183 | diagnostic.severity, | ||
184 | vscode.DiagnosticSeverity.Error | ||
185 | ); | ||
186 | assert.strictEqual( | ||
187 | diagnostic.message, | ||
188 | ['mismatched types', 'expected usize, found u32'].join('\n') | ||
189 | ); | ||
190 | assert.strictEqual(diagnostic.code, 'E0308'); | ||
191 | assert.strictEqual(diagnostic.source, 'rustc'); | ||
192 | assert.strictEqual(diagnostic.tags, undefined); | ||
193 | |||
194 | // No related information | ||
195 | assert.deepStrictEqual(diagnostic.relatedInformation, []); | ||
196 | |||
197 | // There are no suggested fixes | ||
198 | assert.strictEqual(suggestedFixes.length, 0); | ||
199 | }); | ||
173 | }); | 200 | }); |