From 500c909c76a5165e3e3c6ff2eacc009c90f08bbe Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 22:17:05 +0300 Subject: internal: diagnostic code is mandatory --- crates/ide/src/diagnostics.rs | 23 +++++++---------------- crates/ide/src/diagnostics/unresolved_module.rs | 12 +++++------- crates/rust-analyzer/src/handlers.rs | 11 +++++------ 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index 253c360bb..815a633e5 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs @@ -51,28 +51,26 @@ impl DiagnosticCode { #[derive(Debug)] pub struct Diagnostic { - // pub name: Option, + pub code: DiagnosticCode, pub message: String, pub range: TextRange, pub severity: Severity, - pub fixes: Option>, pub unused: bool, - pub code: Option, pub experimental: bool, + pub fixes: Option>, } impl Diagnostic { fn new(code: &'static str, message: impl Into, range: TextRange) -> Diagnostic { let message = message.into(); - let code = Some(DiagnosticCode(code)); - Self { + Diagnostic { + code: DiagnosticCode(code), message, range, severity: Severity::Error, - fixes: None, unused: false, - code, experimental: false, + fixes: None, } } @@ -181,15 +179,8 @@ pub(crate) fn diagnostics( } res.retain(|d| { - if let Some(code) = d.code { - if ctx.config.disabled.contains(code.as_str()) { - return false; - } - } - if ctx.config.disable_experimental && d.experimental { - return false; - } - true + !ctx.config.disabled.contains(d.code.as_str()) + && !(ctx.config.disable_experimental && d.experimental) }); res diff --git a/crates/ide/src/diagnostics/unresolved_module.rs b/crates/ide/src/diagnostics/unresolved_module.rs index b1da8f0e1..977b46414 100644 --- a/crates/ide/src/diagnostics/unresolved_module.rs +++ b/crates/ide/src/diagnostics/unresolved_module.rs @@ -65,9 +65,14 @@ mod baz {} expect![[r#" [ Diagnostic { + code: DiagnosticCode( + "unresolved-module", + ), message: "unresolved module", range: 0..8, severity: Error, + unused: false, + experimental: false, fixes: Some( [ Assist { @@ -98,13 +103,6 @@ mod baz {} }, ], ), - unused: false, - code: Some( - DiagnosticCode( - "unresolved-module", - ), - ), - experimental: false, }, ] "#]], diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs index a81e398c4..ccf66294f 100644 --- a/crates/rust-analyzer/src/handlers.rs +++ b/crates/rust-analyzer/src/handlers.rs @@ -1229,14 +1229,13 @@ pub(crate) fn publish_diagnostics( .map(|d| Diagnostic { 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: d.code.and_then(|code| { - lsp_types::Url::parse(&format!( + code: Some(NumberOrString::String(d.code.as_str().to_string())), + code_description: Some(lsp_types::CodeDescription { + href: lsp_types::Url::parse(&format!( "https://rust-analyzer.github.io/manual.html#{}", - code.as_str() + d.code.as_str() )) - .ok() - .map(|href| lsp_types::CodeDescription { href }) + .unwrap(), }), source: Some("rust-analyzer".to_string()), message: d.message, -- cgit v1.2.3