diff options
author | Ryan Cumming <[email protected]> | 2019-06-27 12:30:23 +0100 |
---|---|---|
committer | Ryan Cumming <[email protected]> | 2019-06-29 08:39:36 +0100 |
commit | abc0784e57610a0cceca63301489918015418df6 (patch) | |
tree | 05aec9fef88f31cee82e3507903a1dbcd6b4d30d /editors/code/src/test/utils/diagnotics/vscode.test.ts | |
parent | 0e1912de528b5092c10eedaf94c43c67d5f86f1a (diff) |
Fix `cargo watch` code action filtering
There are two issues with the implementation of `provideCodeActions`
introduced in #1439:
1. We're returning the code action based on the file its diagnostic is
in; not the file the suggested fix is in. I'm not sure how often
fixes are suggested cross-file but it's something we should handle.
2. We're not filtering code actions based on the passed range. The means
if there is any suggestion in a file we'll show an action for every
line of the file. I naively thought that VS Code would filter for us
but that was wrong.
Unfortunately the VS Code `CodeAction` object is very complex - it can
handle edits across multiple files, run commands, etc. This makes it
complex to check them for equality or see if any of their edits
intersects with a specified range.
To make it easier to work with suggestions this introduces a
`SuggestedFix` model object and a `SuggestFixCollection` code action
provider. This is a layer between the raw Rust JSON and VS Code's
`CodeAction`s. I was reluctant to introduce another layer of abstraction
here but my attempt to work directly with VS Code's model objects was
worse.
Diffstat (limited to 'editors/code/src/test/utils/diagnotics/vscode.test.ts')
-rw-r--r-- | editors/code/src/test/utils/diagnotics/vscode.test.ts | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/editors/code/src/test/utils/diagnotics/vscode.test.ts b/editors/code/src/test/utils/diagnotics/vscode.test.ts new file mode 100644 index 000000000..542dec1f5 --- /dev/null +++ b/editors/code/src/test/utils/diagnotics/vscode.test.ts | |||
@@ -0,0 +1,98 @@ | |||
1 | import * as assert from 'assert'; | ||
2 | import * as vscode from 'vscode'; | ||
3 | |||
4 | import { areDiagnosticsEqual } from '../../../utils/diagnostics/vscode'; | ||
5 | |||
6 | const range1 = new vscode.Range( | ||
7 | new vscode.Position(1, 2), | ||
8 | new vscode.Position(3, 4) | ||
9 | ); | ||
10 | |||
11 | const range2 = new vscode.Range( | ||
12 | new vscode.Position(5, 6), | ||
13 | new vscode.Position(7, 8) | ||
14 | ); | ||
15 | |||
16 | describe('areDiagnosticsEqual', () => { | ||
17 | it('should treat identical diagnostics as equal', () => { | ||
18 | const diagnostic1 = new vscode.Diagnostic( | ||
19 | range1, | ||
20 | 'Hello, world!', | ||
21 | vscode.DiagnosticSeverity.Error | ||
22 | ); | ||
23 | |||
24 | const diagnostic2 = new vscode.Diagnostic( | ||
25 | range1, | ||
26 | 'Hello, world!', | ||
27 | vscode.DiagnosticSeverity.Error | ||
28 | ); | ||
29 | |||
30 | assert(areDiagnosticsEqual(diagnostic1, diagnostic2)); | ||
31 | }); | ||
32 | |||
33 | it('should treat diagnostics with different sources as inequal', () => { | ||
34 | const diagnostic1 = new vscode.Diagnostic( | ||
35 | range1, | ||
36 | 'Hello, world!', | ||
37 | vscode.DiagnosticSeverity.Error | ||
38 | ); | ||
39 | diagnostic1.source = 'rustc'; | ||
40 | |||
41 | const diagnostic2 = new vscode.Diagnostic( | ||
42 | range1, | ||
43 | 'Hello, world!', | ||
44 | vscode.DiagnosticSeverity.Error | ||
45 | ); | ||
46 | diagnostic2.source = 'clippy'; | ||
47 | |||
48 | assert(!areDiagnosticsEqual(diagnostic1, diagnostic2)); | ||
49 | }); | ||
50 | |||
51 | it('should treat diagnostics with different ranges as inequal', () => { | ||
52 | const diagnostic1 = new vscode.Diagnostic( | ||
53 | range1, | ||
54 | 'Hello, world!', | ||
55 | vscode.DiagnosticSeverity.Error | ||
56 | ); | ||
57 | |||
58 | const diagnostic2 = new vscode.Diagnostic( | ||
59 | range2, | ||
60 | 'Hello, world!', | ||
61 | vscode.DiagnosticSeverity.Error | ||
62 | ); | ||
63 | |||
64 | assert(!areDiagnosticsEqual(diagnostic1, diagnostic2)); | ||
65 | }); | ||
66 | |||
67 | it('should treat diagnostics with different messages as inequal', () => { | ||
68 | const diagnostic1 = new vscode.Diagnostic( | ||
69 | range1, | ||
70 | 'Hello, world!', | ||
71 | vscode.DiagnosticSeverity.Error | ||
72 | ); | ||
73 | |||
74 | const diagnostic2 = new vscode.Diagnostic( | ||
75 | range1, | ||
76 | 'Goodbye!, world!', | ||
77 | vscode.DiagnosticSeverity.Error | ||
78 | ); | ||
79 | |||
80 | assert(!areDiagnosticsEqual(diagnostic1, diagnostic2)); | ||
81 | }); | ||
82 | |||
83 | it('should treat diagnostics with different severities as inequal', () => { | ||
84 | const diagnostic1 = new vscode.Diagnostic( | ||
85 | range1, | ||
86 | 'Hello, world!', | ||
87 | vscode.DiagnosticSeverity.Warning | ||
88 | ); | ||
89 | |||
90 | const diagnostic2 = new vscode.Diagnostic( | ||
91 | range1, | ||
92 | 'Hello, world!', | ||
93 | vscode.DiagnosticSeverity.Error | ||
94 | ); | ||
95 | |||
96 | assert(!areDiagnosticsEqual(diagnostic1, diagnostic2)); | ||
97 | }); | ||
98 | }); | ||