on master help sign in
Track source and tags in diagnostics (#3898)
commit64b074541363c72534dc86d00053ecbd5511a9ca authorLuke Cycon <luke@lukecycon.com> dateTue 20 Sep 2022, 00:21 (4 years ago) parent130793d
3 files changed+45−4
helix-core/src/diagnostic.rs+8 helix-lsp/src/lib.rs+20−2 helix-term/src/application.rs+17−2
helix-core/src/diagnostic.rs+8
@@ -29,6 +29,12 @@ pub enum NumberOrString {
2929 String(String),
3030}
3131
32+#[derive(Debug, Clone)]
33+pub enum DiagnosticTag {
34+ Unnecessary,
35+ Deprecated,
36+}
37+
3238/// Corresponds to [`lsp_types::Diagnostic`](https://docs.rs/lsp-types/0.91.0/lsp_types/struct.Diagnostic.html)
3339#[derive(Debug, Clone)]
3440pub struct Diagnostic {
@@ -37,4 +43,6 @@ pub struct Diagnostic {
3743 pub message: String,
3844 pub severity: Option<Severity>,
3945 pub code: Option<NumberOrString>,
46+ pub tags: Option<Vec<DiagnosticTag>>,
47+ pub source: Option<String>,
4048}
helix-lsp/src/lib.rs+20−2
@@ -84,15 +84,33 @@ pub mod util {
8484 None => None,
8585 };
8686
87+ let tags = if let Some(ref tags) = diag.tags {
88+ let new_tags = tags
89+ .iter()
90+ .map(|tag| match tag {
91+ helix_core::diagnostic::DiagnosticTag::Unnecessary => {
92+ lsp::DiagnosticTag::UNNECESSARY
93+ }
94+ helix_core::diagnostic::DiagnosticTag::Deprecated => {
95+ lsp::DiagnosticTag::DEPRECATED
96+ }
97+ })
98+ .collect();
99+
100+ Some(new_tags)
101+ } else {
102+ None
103+ };
104+
87105 // TODO: add support for Diagnostic.data
88106 lsp::Diagnostic::new(
89107 range_to_lsp_range(doc, range, offset_encoding),
90108 severity,
91109 code,
92− None,
110+ diag.source.clone(),
93111 diag.message.to_owned(),
94112 None,
95− None,
113+ tags,
96114 )
97115 }
98116
helix-term/src/application.rs+17−2
@@ -2,7 +2,7 @@ use arc_swap::{access::Map, ArcSwap};
22use futures_util::Stream;
33use helix_core::{
44 config::{default_syntax_loader, user_syntax_loader},
5− diagnostic::NumberOrString,
5+ diagnostic::{DiagnosticTag, NumberOrString},
66 pos_at_coords, syntax, Selection,
77};
88use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
@@ -605,13 +605,28 @@ impl Application {
605605 None => None,
606606 };
607607
608+ let tags = if let Some(ref tags) = diagnostic.tags {
609+ let new_tags = tags.iter().filter_map(|tag| {
610+ match *tag {
611+ lsp::DiagnosticTag::DEPRECATED => Some(DiagnosticTag::Deprecated),
612+ lsp::DiagnosticTag::UNNECESSARY => Some(DiagnosticTag::Unnecessary),
613+ _ => None
614+ }
615+ }).collect();
616+
617+ Some(new_tags)
618+ } else {
619+ None
620+ };
621+
608622 Some(Diagnostic {
609623 range: Range { start, end },
610624 line: diagnostic.range.start.line as usize,
611625 message: diagnostic.message.clone(),
612626 severity,
613627 code,
614− // source
628+ tags,
629+ source: diagnostic.source.clone()
615630 })
616631 })
617632 .collect();