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 <lukastw97@gmail.com>
This commit is contained in:
commit
0c9ee2902a
8 changed files with 149 additions and 9 deletions
|
@ -27,7 +27,24 @@
|
|||
"trivially_copy_pass_by_ref",
|
||||
),
|
||||
),
|
||||
code_description: None,
|
||||
code_description: Some(
|
||||
CodeDescription {
|
||||
href: Url {
|
||||
scheme: "https",
|
||||
host: Some(
|
||||
Domain(
|
||||
"rust-lang.github.io",
|
||||
),
|
||||
),
|
||||
port: None,
|
||||
path: "/rust-clippy/master/index.html",
|
||||
query: None,
|
||||
fragment: Some(
|
||||
"trivially_copy_pass_by_ref",
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
source: Some(
|
||||
"clippy",
|
||||
),
|
||||
|
|
|
@ -27,7 +27,24 @@
|
|||
"E0277",
|
||||
),
|
||||
),
|
||||
code_description: None,
|
||||
code_description: Some(
|
||||
CodeDescription {
|
||||
href: Url {
|
||||
scheme: "https",
|
||||
host: Some(
|
||||
Domain(
|
||||
"doc.rust-lang.org",
|
||||
),
|
||||
),
|
||||
port: None,
|
||||
path: "/error-index.html",
|
||||
query: None,
|
||||
fragment: Some(
|
||||
"E0277",
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
source: Some(
|
||||
"rustc",
|
||||
),
|
||||
|
|
|
@ -27,7 +27,24 @@
|
|||
"E0053",
|
||||
),
|
||||
),
|
||||
code_description: None,
|
||||
code_description: Some(
|
||||
CodeDescription {
|
||||
href: Url {
|
||||
scheme: "https",
|
||||
host: Some(
|
||||
Domain(
|
||||
"doc.rust-lang.org",
|
||||
),
|
||||
),
|
||||
port: None,
|
||||
path: "/error-index.html",
|
||||
query: None,
|
||||
fragment: Some(
|
||||
"E0053",
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
source: Some(
|
||||
"rustc",
|
||||
),
|
||||
|
|
|
@ -27,7 +27,24 @@
|
|||
"E0308",
|
||||
),
|
||||
),
|
||||
code_description: None,
|
||||
code_description: Some(
|
||||
CodeDescription {
|
||||
href: Url {
|
||||
scheme: "https",
|
||||
host: Some(
|
||||
Domain(
|
||||
"doc.rust-lang.org",
|
||||
),
|
||||
),
|
||||
port: None,
|
||||
path: "/error-index.html",
|
||||
query: None,
|
||||
fragment: Some(
|
||||
"E0308",
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
source: Some(
|
||||
"rustc",
|
||||
),
|
||||
|
|
|
@ -27,7 +27,24 @@
|
|||
"E0061",
|
||||
),
|
||||
),
|
||||
code_description: None,
|
||||
code_description: Some(
|
||||
CodeDescription {
|
||||
href: Url {
|
||||
scheme: "https",
|
||||
host: Some(
|
||||
Domain(
|
||||
"doc.rust-lang.org",
|
||||
),
|
||||
),
|
||||
port: None,
|
||||
path: "/error-index.html",
|
||||
query: None,
|
||||
fragment: Some(
|
||||
"E0061",
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
source: Some(
|
||||
"rustc",
|
||||
),
|
||||
|
|
|
@ -27,7 +27,24 @@
|
|||
"let_and_return",
|
||||
),
|
||||
),
|
||||
code_description: None,
|
||||
code_description: Some(
|
||||
CodeDescription {
|
||||
href: Url {
|
||||
scheme: "https",
|
||||
host: Some(
|
||||
Domain(
|
||||
"rust-lang.github.io",
|
||||
),
|
||||
),
|
||||
port: None,
|
||||
path: "/rust-clippy/master/index.html",
|
||||
query: None,
|
||||
fragment: Some(
|
||||
"let_and_return",
|
||||
),
|
||||
},
|
||||
},
|
||||
),
|
||||
source: Some(
|
||||
"clippy",
|
||||
),
|
||||
|
|
|
@ -211,6 +211,12 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
|
|||
}
|
||||
}
|
||||
|
||||
let code_description = match source.as_str() {
|
||||
"rustc" => rustc_code_description(code.as_deref()),
|
||||
"clippy" => clippy_code_description(code.as_deref()),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
primary_spans
|
||||
.iter()
|
||||
.map(|primary_span| {
|
||||
|
@ -248,7 +254,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
|
|||
range: in_macro_location.range,
|
||||
severity,
|
||||
code: code.clone().map(lsp_types::NumberOrString::String),
|
||||
code_description: None,
|
||||
code_description: code_description.clone(),
|
||||
source: Some(source.clone()),
|
||||
message: message.clone(),
|
||||
related_information: Some(information_for_additional_diagnostic),
|
||||
|
@ -269,7 +275,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
|
|||
range: location.range,
|
||||
severity,
|
||||
code: code.clone().map(lsp_types::NumberOrString::String),
|
||||
code_description: None,
|
||||
code_description: code_description.clone(),
|
||||
source: Some(source.clone()),
|
||||
message,
|
||||
related_information: if related_information.is_empty() {
|
||||
|
@ -292,6 +298,31 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn rustc_code_description(code: Option<&str>) -> Option<lsp_types::CodeDescription> {
|
||||
code.filter(|code| {
|
||||
let mut chars = code.chars();
|
||||
chars.next().map_or(false, |c| c == 'E')
|
||||
&& chars.by_ref().take(4).all(|c| c.is_ascii_digit())
|
||||
&& chars.next().is_none()
|
||||
})
|
||||
.and_then(|code| {
|
||||
lsp_types::Url::parse(&format!("https://doc.rust-lang.org/error-index.html#{}", code))
|
||||
.ok()
|
||||
.map(|href| lsp_types::CodeDescription { href })
|
||||
})
|
||||
}
|
||||
|
||||
fn clippy_code_description(code: Option<&str>) -> Option<lsp_types::CodeDescription> {
|
||||
code.and_then(|code| {
|
||||
lsp_types::Url::parse(&format!(
|
||||
"https://rust-lang.github.io/rust-clippy/master/index.html#{}",
|
||||
code
|
||||
))
|
||||
.ok()
|
||||
.map(|href| lsp_types::CodeDescription { href })
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(not(windows))]
|
||||
mod tests {
|
||||
|
|
|
@ -1129,7 +1129,14 @@ pub(crate) fn publish_diagnostics(
|
|||
range: to_proto::range(&line_index, d.range),
|
||||
severity: Some(to_proto::diagnostic_severity(d.severity)),
|
||||
code: d.code.map(|d| d.as_str().to_owned()).map(NumberOrString::String),
|
||||
code_description: None,
|
||||
code_description: d.code.and_then(|code| {
|
||||
lsp_types::Url::parse(&format!(
|
||||
"https://rust-analyzer.github.io/manual.html#{}",
|
||||
code.as_str()
|
||||
))
|
||||
.ok()
|
||||
.map(|href| lsp_types::CodeDescription { href })
|
||||
}),
|
||||
source: Some("rust-analyzer".to_string()),
|
||||
message: d.message,
|
||||
related_information: None,
|
||||
|
|
Loading…
Add table
Reference in a new issue