Skip to content

Commit 9b41eff

Browse files
Improve rustc diagnostic mapping
1 parent fd7c454 commit 9b41eff

File tree

3 files changed

+272
-49
lines changed

3 files changed

+272
-49
lines changed

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

Lines changed: 117 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,94 @@
2121
character: 26,
2222
},
2323
},
24+
severity: Some(
25+
Hint,
26+
),
27+
code: Some(
28+
String(
29+
"E0277",
30+
),
31+
),
32+
code_description: Some(
33+
CodeDescription {
34+
href: Url {
35+
scheme: "https",
36+
username: "",
37+
password: None,
38+
host: Some(
39+
Domain(
40+
"doc.rust-lang.org",
41+
),
42+
),
43+
port: None,
44+
path: "/error-index.html",
45+
query: None,
46+
fragment: Some(
47+
"E0277",
48+
),
49+
},
50+
},
51+
),
52+
source: Some(
53+
"rustc",
54+
),
55+
message: "can\'t compare `{integer}` with `&str`\nthe trait `std::cmp::PartialEq<&str>` is not implemented for `{integer}`",
56+
related_information: Some(
57+
[
58+
DiagnosticRelatedInformation {
59+
location: Location {
60+
uri: Url {
61+
scheme: "file",
62+
username: "",
63+
password: None,
64+
host: None,
65+
port: None,
66+
path: "/test/%3C::core::macros::assert_eq%20macros%3E",
67+
query: None,
68+
fragment: None,
69+
},
70+
range: Range {
71+
start: Position {
72+
line: 6,
73+
character: 30,
74+
},
75+
end: Position {
76+
line: 6,
77+
character: 32,
78+
},
79+
},
80+
},
81+
message: "Exact error occurred here",
82+
},
83+
],
84+
),
85+
tags: None,
86+
data: None,
87+
},
88+
fixes: [],
89+
},
90+
MappedRustDiagnostic {
91+
url: Url {
92+
scheme: "file",
93+
username: "",
94+
password: None,
95+
host: None,
96+
port: None,
97+
path: "/test/%3C::core::macros::assert_eq%20macros%3E",
98+
query: None,
99+
fragment: None,
100+
},
101+
diagnostic: Diagnostic {
102+
range: Range {
103+
start: Position {
104+
line: 6,
105+
character: 30,
106+
},
107+
end: Position {
108+
line: 6,
109+
character: 32,
110+
},
111+
},
24112
severity: Some(
25113
Error,
26114
),
@@ -53,7 +141,35 @@
53141
"rustc",
54142
),
55143
message: "can\'t compare `{integer}` with `&str`\nthe trait `std::cmp::PartialEq<&str>` is not implemented for `{integer}`",
56-
related_information: None,
144+
related_information: Some(
145+
[
146+
DiagnosticRelatedInformation {
147+
location: Location {
148+
uri: Url {
149+
scheme: "file",
150+
username: "",
151+
password: None,
152+
host: None,
153+
port: None,
154+
path: "/test/src/main.rs",
155+
query: None,
156+
fragment: None,
157+
},
158+
range: Range {
159+
start: Position {
160+
line: 1,
161+
character: 4,
162+
},
163+
end: Position {
164+
line: 1,
165+
character: 26,
166+
},
167+
},
168+
},
169+
message: "Error originated from macro call here",
170+
},
171+
],
172+
),
57173
tags: None,
58174
data: None,
59175
},

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

Lines changed: 128 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
diagnostic: Diagnostic {
1414
range: Range {
1515
start: Position {
16-
line: 264,
16+
line: 271,
1717
character: 8,
1818
},
1919
end: Position {
20-
line: 264,
21-
character: 76,
20+
line: 271,
21+
character: 50,
2222
},
2323
},
2424
severity: Some(
25-
Error,
25+
Hint,
2626
),
2727
code: None,
2828
code_description: None,
@@ -40,18 +40,18 @@
4040
password: None,
4141
host: None,
4242
port: None,
43-
path: "/test/crates/hir_def/src/data.rs",
43+
path: "/test/crates/hir_def/src/path.rs",
4444
query: None,
4545
fragment: None,
4646
},
4747
range: Range {
4848
start: Position {
49-
line: 79,
50-
character: 15,
49+
line: 264,
50+
character: 8,
5151
},
5252
end: Position {
53-
line: 79,
54-
character: 41,
53+
line: 264,
54+
character: 76,
5555
},
5656
},
5757
},
@@ -86,6 +86,71 @@
8686
character: 41,
8787
},
8888
},
89+
severity: Some(
90+
Hint,
91+
),
92+
code: None,
93+
code_description: None,
94+
source: Some(
95+
"rustc",
96+
),
97+
message: "Please register your known path in the path module",
98+
related_information: Some(
99+
[
100+
DiagnosticRelatedInformation {
101+
location: Location {
102+
uri: Url {
103+
scheme: "file",
104+
username: "",
105+
password: None,
106+
host: None,
107+
port: None,
108+
path: "/test/crates/hir_def/src/path.rs",
109+
query: None,
110+
fragment: None,
111+
},
112+
range: Range {
113+
start: Position {
114+
line: 264,
115+
character: 8,
116+
},
117+
end: Position {
118+
line: 264,
119+
character: 76,
120+
},
121+
},
122+
},
123+
message: "Exact error occurred here",
124+
},
125+
],
126+
),
127+
tags: None,
128+
data: None,
129+
},
130+
fixes: [],
131+
},
132+
MappedRustDiagnostic {
133+
url: Url {
134+
scheme: "file",
135+
username: "",
136+
password: None,
137+
host: None,
138+
port: None,
139+
path: "/test/crates/hir_def/src/path.rs",
140+
query: None,
141+
fragment: None,
142+
},
143+
diagnostic: Diagnostic {
144+
range: Range {
145+
start: Position {
146+
line: 264,
147+
character: 8,
148+
},
149+
end: Position {
150+
line: 264,
151+
character: 76,
152+
},
153+
},
89154
severity: Some(
90155
Error,
91156
),
@@ -95,7 +160,60 @@
95160
"rustc",
96161
),
97162
message: "Please register your known path in the path module",
98-
related_information: None,
163+
related_information: Some(
164+
[
165+
DiagnosticRelatedInformation {
166+
location: Location {
167+
uri: Url {
168+
scheme: "file",
169+
username: "",
170+
password: None,
171+
host: None,
172+
port: None,
173+
path: "/test/crates/hir_def/src/path.rs",
174+
query: None,
175+
fragment: None,
176+
},
177+
range: Range {
178+
start: Position {
179+
line: 271,
180+
character: 8,
181+
},
182+
end: Position {
183+
line: 271,
184+
character: 50,
185+
},
186+
},
187+
},
188+
message: "Error originated from macro call here",
189+
},
190+
DiagnosticRelatedInformation {
191+
location: Location {
192+
uri: Url {
193+
scheme: "file",
194+
username: "",
195+
password: None,
196+
host: None,
197+
port: None,
198+
path: "/test/crates/hir_def/src/data.rs",
199+
query: None,
200+
fragment: None,
201+
},
202+
range: Range {
203+
start: Position {
204+
line: 79,
205+
character: 15,
206+
},
207+
end: Position {
208+
line: 79,
209+
character: 41,
210+
},
211+
},
212+
},
213+
message: "Error originated from macro call here",
214+
},
215+
],
216+
),
99217
tags: None,
100218
data: None,
101219
},

0 commit comments

Comments
 (0)