aboutsummaryrefslogtreecommitdiff
path: root/crates/rust-analyzer/src/diagnostics
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2020-11-17 20:56:37 +0000
committerLukas Wirth <[email protected]>2020-11-18 07:50:27 +0000
commit863fdcfa249fa4e14f1edc28082bae5f2a7872c7 (patch)
tree4c49a5e7fb0d42df0a42045db31869010740f202 /crates/rust-analyzer/src/diagnostics
parent132063ad9653c21d5393bfd710978f408a0386be (diff)
Link clippy lint codes in diagnostics
Diffstat (limited to 'crates/rust-analyzer/src/diagnostics')
-rw-r--r--crates/rust-analyzer/src/diagnostics/to_proto.rs29
1 files changed, 22 insertions, 7 deletions
diff --git a/crates/rust-analyzer/src/diagnostics/to_proto.rs b/crates/rust-analyzer/src/diagnostics/to_proto.rs
index d3720de33..324019614 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, DiagnosticCode, DiagnosticLevel, DiagnosticSpan}; 5use flycheck::{Applicability, 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,7 +211,11 @@ 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()); 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 };
215 219
216 primary_spans 220 primary_spans
217 .iter() 221 .iter()
@@ -294,20 +298,31 @@ pub(crate) fn map_rust_diagnostic_to_lsp(
294 .collect() 298 .collect()
295} 299}
296 300
297fn rustc_code_description(code: Option<&DiagnosticCode>) -> Option<lsp_types::CodeDescription> { 301fn rustc_code_description(code: Option<&str>) -> Option<lsp_types::CodeDescription> {
298 code.filter(|c| { 302 code.filter(|code| {
299 let mut chars = c.code.chars(); 303 let mut chars = code.chars();
300 chars.next().map_or(false, |c| c == 'E') 304 chars.next().map_or(false, |c| c == 'E')
301 && chars.by_ref().take(4).all(|c| c.is_ascii_digit()) 305 && chars.by_ref().take(4).all(|c| c.is_ascii_digit())
302 && chars.next().is_none() 306 && chars.next().is_none()
303 }) 307 })
304 .and_then(|c| { 308 .and_then(|code| {
305 lsp_types::Url::parse(&format!("https://doc.rust-lang.org/error-index.html#{}", c.code)) 309 lsp_types::Url::parse(&format!("https://doc.rust-lang.org/error-index.html#{}", code))
306 .ok() 310 .ok()
307 .map(|href| lsp_types::CodeDescription { href }) 311 .map(|href| lsp_types::CodeDescription { href })
308 }) 312 })
309} 313}
310 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
311#[cfg(test)] 326#[cfg(test)]
312#[cfg(not(windows))] 327#[cfg(not(windows))]
313mod tests { 328mod tests {