From 64b074541363c72534dc86d00053ecbd5511a9ca Mon Sep 17 00:00:00 2001 From: Luke Cycon Date: Tue, 20 Sep 2022 00:21:15 -0700 Subject: [PATCH] Track source and tags in diagnostics (#3898) --- helix-core/src/diagnostic.rs | 8 ++++++++ helix-lsp/src/lib.rs | 22 ++++++++++++++++++++-- helix-term/src/application.rs | 19 +++++++++++++++++-- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/helix-core/src/diagnostic.rs b/helix-core/src/diagnostic.rs index 48a68dc02..da199ac9c 100644 --- a/helix-core/src/diagnostic.rs +++ b/helix-core/src/diagnostic.rs @@ -29,6 +29,12 @@ pub enum NumberOrString { String(String), } +#[derive(Debug, Clone)] +pub enum DiagnosticTag { + Unnecessary, + Deprecated, +} + /// Corresponds to [`lsp_types::Diagnostic`](https://docs.rs/lsp-types/0.91.0/lsp_types/struct.Diagnostic.html) #[derive(Debug, Clone)] pub struct Diagnostic { @@ -37,4 +43,6 @@ pub struct Diagnostic { pub message: String, pub severity: Option, pub code: Option, + pub tags: Option>, + pub source: Option, } diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index a39325faa..8c76c4a81 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -84,15 +84,33 @@ pub mod util { None => None, }; + let tags = if let Some(ref tags) = diag.tags { + let new_tags = tags + .iter() + .map(|tag| match tag { + helix_core::diagnostic::DiagnosticTag::Unnecessary => { + lsp::DiagnosticTag::UNNECESSARY + } + helix_core::diagnostic::DiagnosticTag::Deprecated => { + lsp::DiagnosticTag::DEPRECATED + } + }) + .collect(); + + Some(new_tags) + } else { + None + }; + // TODO: add support for Diagnostic.data lsp::Diagnostic::new( range_to_lsp_range(doc, range, offset_encoding), severity, code, - None, + diag.source.clone(), diag.message.to_owned(), None, - None, + tags, ) } diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 7ee5b7f1c..496464f01 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -2,7 +2,7 @@ use arc_swap::{access::Map, ArcSwap}; use futures_util::Stream; use helix_core::{ config::{default_syntax_loader, user_syntax_loader}, - diagnostic::NumberOrString, + diagnostic::{DiagnosticTag, NumberOrString}, pos_at_coords, syntax, Selection, }; use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap}; @@ -605,13 +605,28 @@ impl Application { None => None, }; + let tags = if let Some(ref tags) = diagnostic.tags { + let new_tags = tags.iter().filter_map(|tag| { + match *tag { + lsp::DiagnosticTag::DEPRECATED => Some(DiagnosticTag::Deprecated), + lsp::DiagnosticTag::UNNECESSARY => Some(DiagnosticTag::Unnecessary), + _ => None + } + }).collect(); + + Some(new_tags) + } else { + None + }; + Some(Diagnostic { range: Range { start, end }, line: diagnostic.range.start.line as usize, message: diagnostic.message.clone(), severity, code, - // source + tags, + source: diagnostic.source.clone() }) }) .collect();