From 863fdcfa249fa4e14f1edc28082bae5f2a7872c7 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 17 Nov 2020 21:56:37 +0100 Subject: Link clippy lint codes in diagnostics --- crates/rust-analyzer/src/diagnostics/to_proto.rs | 29 ++++++++++++++++++------ 1 file 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 @@ //! `cargo check` json format to the LSP diagnostic format. use std::{collections::HashMap, path::Path}; -use flycheck::{Applicability, DiagnosticCode, DiagnosticLevel, DiagnosticSpan}; +use flycheck::{Applicability, DiagnosticLevel, DiagnosticSpan}; use stdx::format_to; use crate::{lsp_ext, to_proto::url_from_abs_path}; @@ -211,7 +211,11 @@ pub(crate) fn map_rust_diagnostic_to_lsp( } } - let code_description = rustc_code_description(rd.code.as_ref()); + 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() @@ -294,20 +298,31 @@ pub(crate) fn map_rust_diagnostic_to_lsp( .collect() } -fn rustc_code_description(code: Option<&DiagnosticCode>) -> Option { - code.filter(|c| { - let mut chars = c.code.chars(); +fn rustc_code_description(code: Option<&str>) -> Option { + 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(|c| { - lsp_types::Url::parse(&format!("https://doc.rust-lang.org/error-index.html#{}", c.code)) + .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 { + 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 { -- cgit v1.2.3