aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-11-18 14:01:29 +0000
committerGitHub <[email protected]>2020-11-18 14:01:29 +0000
commit0c9ee2902a6368dbb1ee0a62ef23bd000e98e295 (patch)
treeda87cf6a9a6ce3347e47acd9fe0e250b589c4922
parent99975d08f0f1497abc6dc13681f040848595e50b (diff)
parent91a1a836015f61accb73f7b855b852fc22e810fc (diff)
Merge #6585
6585: Link rustc error page and clippy lint page via CodeDescription r=kjeremy a=Veykril Fixes #6371 This makes the error code in here clickable, same for clippy lints ![image](https://user-images.githubusercontent.com/3757771/99459468-6d110b00-292e-11eb-9cde-d43ec9cebc09.png) For clippy I just chose the master build of the site as I believe that to be pretty much always the best fitting. Co-authored-by: Lukas Wirth <[email protected]>
-rw-r--r--crates/rust-analyzer/src/diagnostics/test_data/clippy_pass_by_ref.txt19
-rw-r--r--crates/rust-analyzer/src/diagnostics/test_data/handles_macro_location.txt19
-rw-r--r--crates/rust-analyzer/src/diagnostics/test_data/rustc_incompatible_type_for_trait.txt19
-rw-r--r--crates/rust-analyzer/src/diagnostics/test_data/rustc_mismatched_type.txt19
-rw-r--r--crates/rust-analyzer/src/diagnostics/test_data/rustc_wrong_number_of_parameters.txt19
-rw-r--r--crates/rust-analyzer/src/diagnostics/test_data/snap_multi_line_fix.txt19
-rw-r--r--crates/rust-analyzer/src/diagnostics/to_proto.rs35
-rw-r--r--crates/rust-analyzer/src/handlers.rs9
8 files changed, 149 insertions, 9 deletions
diff --git a/crates/rust-analyzer/src/diagnostics/test_data/clippy_pass_by_ref.txt b/crates/rust-analyzer/src/diagnostics/test_data/clippy_pass_by_ref.txt
index 5b2e5187a..72f6c5725 100644
--- a/crates/rust-analyzer/src/diagnostics/test_data/clippy_pass_by_ref.txt
+++ b/crates/rust-analyzer/src/diagnostics/test_data/clippy_pass_by_ref.txt
@@ -27,7 +27,24 @@
27 "trivially_copy_pass_by_ref", 27 "trivially_copy_pass_by_ref",
28 ), 28 ),
29 ), 29 ),
30 code_description: None, 30 code_description: Some(
31 CodeDescription {
32 href: Url {
33 scheme: "https",
34 host: Some(
35 Domain(
36 "rust-lang.github.io",
37 ),
38 ),
39 port: None,
40 path: "/rust-clippy/master/index.html",
41 query: None,
42 fragment: Some(
43 "trivially_copy_pass_by_ref",
44 ),
45 },
46 },
47 ),
31 source: Some( 48 source: Some(
32 "clippy", 49 "clippy",
33 ), 50 ),
diff --git a/crates/rust-analyzer/src/diagnostics/test_data/handles_macro_location.txt b/crates/rust-analyzer/src/diagnostics/test_data/handles_macro_location.txt
index 116f0ff73..eb4a6b597 100644
--- a/crates/rust-analyzer/src/diagnostics/test_data/handles_macro_location.txt
+++ b/crates/rust-analyzer/src/diagnostics/test_data/handles_macro_location.txt
@@ -27,7 +27,24 @@
27 "E0277", 27 "E0277",
28 ), 28 ),
29 ), 29 ),
30 code_description: None, 30 code_description: Some(
31 CodeDescription {
32 href: Url {
33 scheme: "https",
34 host: Some(
35 Domain(
36 "doc.rust-lang.org",
37 ),
38 ),
39 port: None,
40 path: "/error-index.html",
41 query: None,
42 fragment: Some(
43 "E0277",
44 ),
45 },
46 },
47 ),
31 source: Some( 48 source: Some(
32 "rustc", 49 "rustc",
33 ), 50 ),
diff --git a/crates/rust-analyzer/src/diagnostics/test_data/rustc_incompatible_type_for_trait.txt b/crates/rust-analyzer/src/diagnostics/test_data/rustc_incompatible_type_for_trait.txt
index 2cbf657e5..19f72196d 100644
--- a/crates/rust-analyzer/src/diagnostics/test_data/rustc_incompatible_type_for_trait.txt
+++ b/crates/rust-analyzer/src/diagnostics/test_data/rustc_incompatible_type_for_trait.txt
@@ -27,7 +27,24 @@
27 "E0053", 27 "E0053",
28 ), 28 ),
29 ), 29 ),
30 code_description: None, 30 code_description: Some(
31 CodeDescription {
32 href: Url {
33 scheme: "https",
34 host: Some(
35 Domain(
36 "doc.rust-lang.org",
37 ),
38 ),
39 port: None,
40 path: "/error-index.html",
41 query: None,
42 fragment: Some(
43 "E0053",
44 ),
45 },
46 },
47 ),
31 source: Some( 48 source: Some(
32 "rustc", 49 "rustc",
33 ), 50 ),
diff --git a/crates/rust-analyzer/src/diagnostics/test_data/rustc_mismatched_type.txt b/crates/rust-analyzer/src/diagnostics/test_data/rustc_mismatched_type.txt
index 1142dc2ac..15ac95d72 100644
--- a/crates/rust-analyzer/src/diagnostics/test_data/rustc_mismatched_type.txt
+++ b/crates/rust-analyzer/src/diagnostics/test_data/rustc_mismatched_type.txt
@@ -27,7 +27,24 @@
27 "E0308", 27 "E0308",
28 ), 28 ),
29 ), 29 ),
30 code_description: None, 30 code_description: Some(
31 CodeDescription {
32 href: Url {
33 scheme: "https",
34 host: Some(
35 Domain(
36 "doc.rust-lang.org",
37 ),
38 ),
39 port: None,
40 path: "/error-index.html",
41 query: None,
42 fragment: Some(
43 "E0308",
44 ),
45 },
46 },
47 ),
31 source: Some( 48 source: Some(
32 "rustc", 49 "rustc",
33 ), 50 ),
diff --git a/crates/rust-analyzer/src/diagnostics/test_data/rustc_wrong_number_of_parameters.txt b/crates/rust-analyzer/src/diagnostics/test_data/rustc_wrong_number_of_parameters.txt
index 782c72dbd..b9650f3e4 100644
--- a/crates/rust-analyzer/src/diagnostics/test_data/rustc_wrong_number_of_parameters.txt
+++ b/crates/rust-analyzer/src/diagnostics/test_data/rustc_wrong_number_of_parameters.txt
@@ -27,7 +27,24 @@
27 "E0061", 27 "E0061",
28 ), 28 ),
29 ), 29 ),
30 code_description: None, 30 code_description: Some(
31 CodeDescription {
32 href: Url {
33 scheme: "https",
34 host: Some(
35 Domain(
36 "doc.rust-lang.org",
37 ),
38 ),
39 port: None,
40 path: "/error-index.html",
41 query: None,
42 fragment: Some(
43 "E0061",
44 ),
45 },
46 },
47 ),
31 source: Some( 48 source: Some(
32 "rustc", 49 "rustc",
33 ), 50 ),
diff --git a/crates/rust-analyzer/src/diagnostics/test_data/snap_multi_line_fix.txt b/crates/rust-analyzer/src/diagnostics/test_data/snap_multi_line_fix.txt
index d3f27ab6a..c45f68a91 100644
--- a/crates/rust-analyzer/src/diagnostics/test_data/snap_multi_line_fix.txt
+++ b/crates/rust-analyzer/src/diagnostics/test_data/snap_multi_line_fix.txt
@@ -27,7 +27,24 @@
27 "let_and_return", 27 "let_and_return",
28 ), 28 ),
29 ), 29 ),
30 code_description: None, 30 code_description: Some(
31 CodeDescription {
32 href: Url {
33 scheme: "https",
34 host: Some(
35 Domain(
36 "rust-lang.github.io",
37 ),
38 ),
39 port: None,
40 path: "/rust-clippy/master/index.html",
41 query: None,
42 fragment: Some(
43 "let_and_return",
44 ),
45 },
46 },
47 ),
31 source: Some( 48 source: Some(
32 "clippy", 49 "clippy",
33 ), 50 ),
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs
index 93bef5c8b..324019614 100644
--- a/crates/rust-analyzer/src/diagnostics/to_proto.rs
+++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs
@@ -211,6 +211,12 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
211 } 211 }
212 } 212 }
213 213
214 let code_description = match source.as_str() {
215 "rustc" => rustc_code_description(code.as_deref()),
216 "clippy" => clippy_code_description(code.as_deref()),
217 _ => None,
218 };
219
214 primary_spans 220 primary_spans
215 .iter() 221 .iter()
216 .map(|primary_span| { 222 .map(|primary_span| {
@@ -248,7 +254,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
248 range: in_macro_location.range, 254 range: in_macro_location.range,
249 severity, 255 severity,
250 code: code.clone().map(lsp_types::NumberOrString::String), 256 code: code.clone().map(lsp_types::NumberOrString::String),
251 code_description: None, 257 code_description: code_description.clone(),
252 source: Some(source.clone()), 258 source: Some(source.clone()),
253 message: message.clone(), 259 message: message.clone(),
254 related_information: Some(information_for_additional_diagnostic), 260 related_information: Some(information_for_additional_diagnostic),
@@ -269,7 +275,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
269 range: location.range, 275 range: location.range,
270 severity, 276 severity,
271 code: code.clone().map(lsp_types::NumberOrString::String), 277 code: code.clone().map(lsp_types::NumberOrString::String),
272 code_description: None, 278 code_description: code_description.clone(),
273 source: Some(source.clone()), 279 source: Some(source.clone()),
274 message, 280 message,
275 related_information: if related_information.is_empty() { 281 related_information: if related_information.is_empty() {
@@ -292,6 +298,31 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
292 .collect() 298 .collect()
293} 299}
294 300
301fn rustc_code_description(code: Option<&str>) -> Option<lsp_types::CodeDescription> {
302 code.filter(|code| {
303 let mut chars = code.chars();
304 chars.next().map_or(false, |c| c == 'E')
305 && chars.by_ref().take(4).all(|c| c.is_ascii_digit())
306 && chars.next().is_none()
307 })
308 .and_then(|code| {
309 lsp_types::Url::parse(&format!("https://doc.rust-lang.org/error-index.html#{}", code))
310 .ok()
311 .map(|href| lsp_types::CodeDescription { href })
312 })
313}
314
315fn clippy_code_description(code: Option<&str>) -> Option<lsp_types::CodeDescription> {
316 code.and_then(|code| {
317 lsp_types::Url::parse(&format!(
318 "https://rust-lang.github.io/rust-clippy/master/index.html#{}",
319 code
320 ))
321 .ok()
322 .map(|href| lsp_types::CodeDescription { href })
323 })
324}
325
295#[cfg(test)] 326#[cfg(test)]
296#[cfg(not(windows))] 327#[cfg(not(windows))]
297mod tests { 328mod tests {
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index 118e7276f..1cf4139d2 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -1129,7 +1129,14 @@ pub(crate) fn publish_diagnostics(
1129 range: to_proto::range(&line_index, d.range), 1129 range: to_proto::range(&line_index, d.range),
1130 severity: Some(to_proto::diagnostic_severity(d.severity)), 1130 severity: Some(to_proto::diagnostic_severity(d.severity)),
1131 code: d.code.map(|d| d.as_str().to_owned()).map(NumberOrString::String), 1131 code: d.code.map(|d| d.as_str().to_owned()).map(NumberOrString::String),
1132 code_description: None, 1132 code_description: d.code.and_then(|code| {
1133 lsp_types::Url::parse(&format!(
1134 "https://rust-analyzer.github.io/manual.html#{}",
1135 code.as_str()
1136 ))
1137 .ok()
1138 .map(|href| lsp_types::CodeDescription { href })
1139 }),
1133 source: Some("rust-analyzer".to_string()), 1140 source: Some("rust-analyzer".to_string()),
1134 message: d.message, 1141 message: d.message,
1135 related_information: None, 1142 related_information: None,