diff options
Diffstat (limited to 'editors/code/src/utils')
-rw-r--r-- | editors/code/src/utils/rust_diagnostics.ts | 14 | ||||
-rw-r--r-- | editors/code/src/utils/vscode_diagnostics.ts | 73 |
2 files changed, 85 insertions, 2 deletions
diff --git a/editors/code/src/utils/rust_diagnostics.ts b/editors/code/src/utils/rust_diagnostics.ts index ed049c95e..3c524cb37 100644 --- a/editors/code/src/utils/rust_diagnostics.ts +++ b/editors/code/src/utils/rust_diagnostics.ts | |||
@@ -187,8 +187,18 @@ export function mapRustDiagnosticToVsCode( | |||
187 | 187 | ||
188 | const vd = new vscode.Diagnostic(location.range, rd.message, severity); | 188 | const vd = new vscode.Diagnostic(location.range, rd.message, severity); |
189 | 189 | ||
190 | vd.source = 'rustc'; | 190 | let source = 'rustc'; |
191 | vd.code = rd.code ? rd.code.code : undefined; | 191 | let code = rd.code && rd.code.code; |
192 | if (code) { | ||
193 | // See if this is an RFC #2103 scoped lint (e.g. from Clippy) | ||
194 | const scopedCode = code.split('::'); | ||
195 | if (scopedCode.length === 2) { | ||
196 | [source, code] = scopedCode; | ||
197 | } | ||
198 | } | ||
199 | |||
200 | vd.source = source; | ||
201 | vd.code = code; | ||
192 | vd.relatedInformation = []; | 202 | vd.relatedInformation = []; |
193 | 203 | ||
194 | for (const secondarySpan of secondarySpans) { | 204 | for (const secondarySpan of secondarySpans) { |
diff --git a/editors/code/src/utils/vscode_diagnostics.ts b/editors/code/src/utils/vscode_diagnostics.ts new file mode 100644 index 000000000..9d763c8d6 --- /dev/null +++ b/editors/code/src/utils/vscode_diagnostics.ts | |||
@@ -0,0 +1,73 @@ | |||
1 | import * as vscode from 'vscode'; | ||
2 | |||
3 | /** Compares two `vscode.Diagnostic`s for equality */ | ||
4 | export function areDiagnosticsEqual( | ||
5 | left: vscode.Diagnostic, | ||
6 | right: vscode.Diagnostic | ||
7 | ): boolean { | ||
8 | return ( | ||
9 | left.source === right.source && | ||
10 | left.severity === right.severity && | ||
11 | left.range.isEqual(right.range) && | ||
12 | left.message === right.message | ||
13 | ); | ||
14 | } | ||
15 | |||
16 | /** Compares two `vscode.TextEdit`s for equality */ | ||
17 | function areTextEditsEqual( | ||
18 | left: vscode.TextEdit, | ||
19 | right: vscode.TextEdit | ||
20 | ): boolean { | ||
21 | if (!left.range.isEqual(right.range)) { | ||
22 | return false; | ||
23 | } | ||
24 | |||
25 | if (left.newText !== right.newText) { | ||
26 | return false; | ||
27 | } | ||
28 | |||
29 | return true; | ||
30 | } | ||
31 | |||
32 | /** Compares two `vscode.CodeAction`s for equality */ | ||
33 | export function areCodeActionsEqual( | ||
34 | left: vscode.CodeAction, | ||
35 | right: vscode.CodeAction | ||
36 | ): boolean { | ||
37 | if ( | ||
38 | left.kind !== right.kind || | ||
39 | left.title !== right.title || | ||
40 | !left.edit || | ||
41 | !right.edit | ||
42 | ) { | ||
43 | return false; | ||
44 | } | ||
45 | |||
46 | const leftEditEntries = left.edit.entries(); | ||
47 | const rightEditEntries = right.edit.entries(); | ||
48 | |||
49 | if (leftEditEntries.length !== rightEditEntries.length) { | ||
50 | return false; | ||
51 | } | ||
52 | |||
53 | for (let i = 0; i < leftEditEntries.length; i++) { | ||
54 | const [leftUri, leftEdits] = leftEditEntries[i]; | ||
55 | const [rightUri, rightEdits] = rightEditEntries[i]; | ||
56 | |||
57 | if (leftUri.toString() !== rightUri.toString()) { | ||
58 | return false; | ||
59 | } | ||
60 | |||
61 | if (leftEdits.length !== rightEdits.length) { | ||
62 | return false; | ||
63 | } | ||
64 | |||
65 | for (let j = 0; j < leftEdits.length; j++) { | ||
66 | if (!areTextEditsEqual(leftEdits[j], rightEdits[j])) { | ||
67 | return false; | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | |||
72 | return true; | ||
73 | } | ||