Skip to content

Commit 1403ddf

Browse files
Merge #6734
6734: Emit additional diagnostics for hints/help/etc r=lnicola a=jonas-schievink This makes rust-analyzer diagnostics match native rustc diagnostics in the terminal more closely. Unfortunately all of this is a bodge, since we already provide this information to the client in the form of `DiagnosticRelatedInformation`, but at least VS Code chooses such a poor UI for these that they don't help much, as evidenced [here](https://twitter.com/yaahc_/status/1335297260444250112) and in rust-lang/rust#79741. This PR papers over these client UI problems by taking the `DiagnosticRelatedInformation` and turning each one into its own hint-level diagnostic, which makes it show up in the source code. Quick fixes are attached to all resulting diagnostics, which makes them more discoverable. ### Example: "Consider removing this semicolon" ![screenshot-2020-12-06-01:27:29](https://user-images.githubusercontent.com/1786438/101268366-46423980-3762-11eb-9a69-1ff0b1806c2f.png) ![screenshot-2020-12-06-01:27:39](https://user-images.githubusercontent.com/1786438/101268367-46dad000-3762-11eb-81fa-afd234d44f17.png) ![screenshot-2020-12-06-01:27:46](https://user-images.githubusercontent.com/1786438/101268368-46dad000-3762-11eb-9205-4b9bd9f4406d.png) ### Example: "Value used after move" ![screenshot-2020-12-06-01:33:00](https://user-images.githubusercontent.com/1786438/101268447-22332800-3763-11eb-85ce-8c742927a2c8.png) ![screenshot-2020-12-06-01:33:07](https://user-images.githubusercontent.com/1786438/101268448-22cbbe80-3763-11eb-8f16-0590895d8bc6.png) Co-authored-by: Jonas Schievink <[email protected]>
2 parents 8d5aa08 + 45b8b3d commit 1403ddf

File tree

8 files changed

+1093
-119
lines changed

8 files changed

+1093
-119
lines changed

crates/rust-analyzer/src/diagnostics/test_data/clippy_pass_by_ref.txt

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,168 @@
104104
},
105105
fixes: [],
106106
},
107+
MappedRustDiagnostic {
108+
url: Url {
109+
scheme: "file",
110+
host: None,
111+
port: None,
112+
path: "/test/compiler/lib.rs",
113+
query: None,
114+
fragment: None,
115+
},
116+
diagnostic: Diagnostic {
117+
range: Range {
118+
start: Position {
119+
line: 0,
120+
character: 8,
121+
},
122+
end: Position {
123+
line: 0,
124+
character: 19,
125+
},
126+
},
127+
severity: Some(
128+
Hint,
129+
),
130+
code: Some(
131+
String(
132+
"trivially_copy_pass_by_ref",
133+
),
134+
),
135+
code_description: Some(
136+
CodeDescription {
137+
href: Url {
138+
scheme: "https",
139+
host: Some(
140+
Domain(
141+
"rust-lang.github.io",
142+
),
143+
),
144+
port: None,
145+
path: "/rust-clippy/master/index.html",
146+
query: None,
147+
fragment: Some(
148+
"trivially_copy_pass_by_ref",
149+
),
150+
},
151+
},
152+
),
153+
source: Some(
154+
"clippy",
155+
),
156+
message: "lint level defined here",
157+
related_information: Some(
158+
[
159+
DiagnosticRelatedInformation {
160+
location: Location {
161+
uri: Url {
162+
scheme: "file",
163+
host: None,
164+
port: None,
165+
path: "/test/compiler/mir/tagset.rs",
166+
query: None,
167+
fragment: None,
168+
},
169+
range: Range {
170+
start: Position {
171+
line: 41,
172+
character: 23,
173+
},
174+
end: Position {
175+
line: 41,
176+
character: 28,
177+
},
178+
},
179+
},
180+
message: "original diagnostic",
181+
},
182+
],
183+
),
184+
tags: None,
185+
data: None,
186+
},
187+
fixes: [],
188+
},
189+
MappedRustDiagnostic {
190+
url: Url {
191+
scheme: "file",
192+
host: None,
193+
port: None,
194+
path: "/test/compiler/mir/tagset.rs",
195+
query: None,
196+
fragment: None,
197+
},
198+
diagnostic: Diagnostic {
199+
range: Range {
200+
start: Position {
201+
line: 41,
202+
character: 23,
203+
},
204+
end: Position {
205+
line: 41,
206+
character: 28,
207+
},
208+
},
209+
severity: Some(
210+
Hint,
211+
),
212+
code: Some(
213+
String(
214+
"trivially_copy_pass_by_ref",
215+
),
216+
),
217+
code_description: Some(
218+
CodeDescription {
219+
href: Url {
220+
scheme: "https",
221+
host: Some(
222+
Domain(
223+
"rust-lang.github.io",
224+
),
225+
),
226+
port: None,
227+
path: "/rust-clippy/master/index.html",
228+
query: None,
229+
fragment: Some(
230+
"trivially_copy_pass_by_ref",
231+
),
232+
},
233+
},
234+
),
235+
source: Some(
236+
"clippy",
237+
),
238+
message: "consider passing by value instead",
239+
related_information: Some(
240+
[
241+
DiagnosticRelatedInformation {
242+
location: Location {
243+
uri: Url {
244+
scheme: "file",
245+
host: None,
246+
port: None,
247+
path: "/test/compiler/mir/tagset.rs",
248+
query: None,
249+
fragment: None,
250+
},
251+
range: Range {
252+
start: Position {
253+
line: 41,
254+
character: 23,
255+
},
256+
end: Position {
257+
line: 41,
258+
character: 28,
259+
},
260+
},
261+
},
262+
message: "original diagnostic",
263+
},
264+
],
265+
),
266+
tags: None,
267+
data: None,
268+
},
269+
fixes: [],
270+
},
107271
]

crates/rust-analyzer/src/diagnostics/test_data/macro_compiler_error.txt

Lines changed: 17 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
scheme: "file",
55
host: None,
66
port: None,
7-
path: "/test/crates/hir_def/src/data.rs",
7+
path: "/test/crates/hir_def/src/path.rs",
88
query: None,
99
fragment: None,
1010
},
1111
diagnostic: Diagnostic {
1212
range: Range {
1313
start: Position {
14-
line: 79,
15-
character: 15,
14+
line: 264,
15+
character: 8,
1616
},
1717
end: Position {
18-
line: 79,
19-
character: 41,
18+
line: 264,
19+
character: 76,
2020
},
2121
},
2222
severity: Some(
@@ -36,22 +36,22 @@
3636
scheme: "file",
3737
host: None,
3838
port: None,
39-
path: "/test/crates/hir_def/src/path.rs",
39+
path: "/test/crates/hir_def/src/data.rs",
4040
query: None,
4141
fragment: None,
4242
},
4343
range: Range {
4444
start: Position {
45-
line: 264,
46-
character: 8,
45+
line: 79,
46+
character: 15,
4747
},
4848
end: Position {
49-
line: 264,
50-
character: 76,
49+
line: 79,
50+
character: 41,
5151
},
5252
},
5353
},
54-
message: "Error originated from macro here",
54+
message: "Exact error occurred here",
5555
},
5656
],
5757
),
@@ -65,19 +65,19 @@
6565
scheme: "file",
6666
host: None,
6767
port: None,
68-
path: "/test/crates/hir_def/src/path.rs",
68+
path: "/test/crates/hir_def/src/data.rs",
6969
query: None,
7070
fragment: None,
7171
},
7272
diagnostic: Diagnostic {
7373
range: Range {
7474
start: Position {
75-
line: 264,
76-
character: 8,
75+
line: 79,
76+
character: 15,
7777
},
7878
end: Position {
79-
line: 264,
80-
character: 76,
79+
line: 79,
80+
character: 41,
8181
},
8282
},
8383
severity: Some(
@@ -89,33 +89,7 @@
8989
"rustc",
9090
),
9191
message: "Please register your known path in the path module",
92-
related_information: Some(
93-
[
94-
DiagnosticRelatedInformation {
95-
location: Location {
96-
uri: Url {
97-
scheme: "file",
98-
host: None,
99-
port: None,
100-
path: "/test/crates/hir_def/src/data.rs",
101-
query: None,
102-
fragment: None,
103-
},
104-
range: Range {
105-
start: Position {
106-
line: 79,
107-
character: 15,
108-
},
109-
end: Position {
110-
line: 79,
111-
character: 41,
112-
},
113-
},
114-
},
115-
message: "Exact error occured here",
116-
},
117-
],
118-
),
92+
related_information: None,
11993
tags: None,
12094
data: None,
12195
},

0 commit comments

Comments
 (0)