aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/diagnostics/to_proto.rs22
1 files changed, 19 insertions, 3 deletions
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs
index 93bef5c8b..d3720de33 100644
--- a/crates/rust-analyzer/src/diagnostics/to_proto.rs
+++ b/crates/rust-analyzer/src/diagnostics/to_proto.rs
@@ -2,7 +2,7 @@
2//! `cargo check` json format to the LSP diagnostic format. 2//! `cargo check` json format to the LSP diagnostic format.
3use std::{collections::HashMap, path::Path}; 3use std::{collections::HashMap, path::Path};
4 4
5use flycheck::{Applicability, DiagnosticLevel, DiagnosticSpan}; 5use flycheck::{Applicability, DiagnosticCode, DiagnosticLevel, DiagnosticSpan};
6use stdx::format_to; 6use stdx::format_to;
7 7
8use crate::{lsp_ext, to_proto::url_from_abs_path}; 8use crate::{lsp_ext, to_proto::url_from_abs_path};
@@ -211,6 +211,8 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
211 } 211 }
212 } 212 }
213 213
214 let code_description = rustc_code_description(rd.code.as_ref());
215
214 primary_spans 216 primary_spans
215 .iter() 217 .iter()
216 .map(|primary_span| { 218 .map(|primary_span| {
@@ -248,7 +250,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
248 range: in_macro_location.range, 250 range: in_macro_location.range,
249 severity, 251 severity,
250 code: code.clone().map(lsp_types::NumberOrString::String), 252 code: code.clone().map(lsp_types::NumberOrString::String),
251 code_description: None, 253 code_description: code_description.clone(),
252 source: Some(source.clone()), 254 source: Some(source.clone()),
253 message: message.clone(), 255 message: message.clone(),
254 related_information: Some(information_for_additional_diagnostic), 256 related_information: Some(information_for_additional_diagnostic),
@@ -269,7 +271,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
269 range: location.range, 271 range: location.range,
270 severity, 272 severity,
271 code: code.clone().map(lsp_types::NumberOrString::String), 273 code: code.clone().map(lsp_types::NumberOrString::String),
272 code_description: None, 274 code_description: code_description.clone(),
273 source: Some(source.clone()), 275 source: Some(source.clone()),
274 message, 276 message,
275 related_information: if related_information.is_empty() { 277 related_information: if related_information.is_empty() {
@@ -292,6 +294,20 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
292 .collect() 294 .collect()
293} 295}
294 296
297fn rustc_code_description(code: Option<&DiagnosticCode>) -> Option<lsp_types::CodeDescription> {
298 code.filter(|c| {
299 let mut chars = c.code.chars();
300 chars.next().map_or(false, |c| c == 'E')
301 && chars.by_ref().take(4).all(|c| c.is_ascii_digit())
302 && chars.next().is_none()
303 })
304 .and_then(|c| {
305 lsp_types::Url::parse(&format!("https://doc.rust-lang.org/error-index.html#{}", c.code))
306 .ok()
307 .map(|href| lsp_types::CodeDescription { href })
308 })
309}
310
295#[cfg(test)] 311#[cfg(test)]
296#[cfg(not(windows))] 312#[cfg(not(windows))]
297mod tests { 313mod tests {