mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
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  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",
|
"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(
|
source: Some(
|
||||||
"clippy",
|
"clippy",
|
||||||
),
|
),
|
||||||
|
|
|
@ -27,7 +27,24 @@
|
||||||
"E0277",
|
"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(
|
source: Some(
|
||||||
"rustc",
|
"rustc",
|
||||||
),
|
),
|
||||||
|
|
|
@ -27,7 +27,24 @@
|
||||||
"E0053",
|
"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(
|
source: Some(
|
||||||
"rustc",
|
"rustc",
|
||||||
),
|
),
|
||||||
|
|
|
@ -27,7 +27,24 @@
|
||||||
"E0308",
|
"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(
|
source: Some(
|
||||||
"rustc",
|
"rustc",
|
||||||
),
|
),
|
||||||
|
|
|
@ -27,7 +27,24 @@
|
||||||
"E0061",
|
"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(
|
source: Some(
|
||||||
"rustc",
|
"rustc",
|
||||||
),
|
),
|
||||||
|
|
|
@ -27,7 +27,24 @@
|
||||||
"let_and_return",
|
"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(
|
source: Some(
|
||||||
"clippy",
|
"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
|
primary_spans
|
||||||
.iter()
|
.iter()
|
||||||
.map(|primary_span| {
|
.map(|primary_span| {
|
||||||
|
@ -248,7 +254,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
|
||||||
range: in_macro_location.range,
|
range: in_macro_location.range,
|
||||||
severity,
|
severity,
|
||||||
code: code.clone().map(lsp_types::NumberOrString::String),
|
code: code.clone().map(lsp_types::NumberOrString::String),
|
||||||
code_description: None,
|
code_description: code_description.clone(),
|
||||||
source: Some(source.clone()),
|
source: Some(source.clone()),
|
||||||
message: message.clone(),
|
message: message.clone(),
|
||||||
related_information: Some(information_for_additional_diagnostic),
|
related_information: Some(information_for_additional_diagnostic),
|
||||||
|
@ -269,7 +275,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
|
||||||
range: location.range,
|
range: location.range,
|
||||||
severity,
|
severity,
|
||||||
code: code.clone().map(lsp_types::NumberOrString::String),
|
code: code.clone().map(lsp_types::NumberOrString::String),
|
||||||
code_description: None,
|
code_description: code_description.clone(),
|
||||||
source: Some(source.clone()),
|
source: Some(source.clone()),
|
||||||
message,
|
message,
|
||||||
related_information: if related_information.is_empty() {
|
related_information: if related_information.is_empty() {
|
||||||
|
@ -292,6 +298,31 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
|
||||||
.collect()
|
.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(test)]
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
|
@ -1129,7 +1129,14 @@ pub(crate) fn publish_diagnostics(
|
||||||
range: to_proto::range(&line_index, d.range),
|
range: to_proto::range(&line_index, d.range),
|
||||||
severity: Some(to_proto::diagnostic_severity(d.severity)),
|
severity: Some(to_proto::diagnostic_severity(d.severity)),
|
||||||
code: d.code.map(|d| d.as_str().to_owned()).map(NumberOrString::String),
|
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()),
|
source: Some("rust-analyzer".to_string()),
|
||||||
message: d.message,
|
message: d.message,
|
||||||
related_information: None,
|
related_information: None,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue