on master help sign in
Track source and tags in diagnostics (#3898)
64b0745Luke Cycon
helix-core/src/diagnostic.rs+8
@@ -29,6 +29,12 @@ pub enum NumberOrString {
29 String(String),
29 String(String),
30}
30}
31
31
32+#[derive(Debug, Clone)]
33+pub enum DiagnosticTag {
34+ Unnecessary,
35+ Deprecated,
36+}
37+
32/// Corresponds to [`lsp_types::Diagnostic`](https://docs.rs/lsp-types/0.91.0/lsp_types/struct.Diagnostic.html)
38/// Corresponds to [`lsp_types::Diagnostic`](https://docs.rs/lsp-types/0.91.0/lsp_types/struct.Diagnostic.html)
33#[derive(Debug, Clone)]
39#[derive(Debug, Clone)]
34pub struct Diagnostic {
40pub struct Diagnostic {
@@ -37,4 +43,6 @@ pub struct Diagnostic {
37 pub message: String,
43 pub message: String,
38 pub severity: Option<Severity>,
44 pub severity: Option<Severity>,
39 pub code: Option<NumberOrString>,
45 pub code: Option<NumberOrString>,
46+ pub tags: Option<Vec<DiagnosticTag>>,
47+ pub source: Option<String>,
40}
48}
helix-lsp/src/lib.rs+20−2
@@ -84,15 +84,33 @@ pub mod util {
84 None => None,
84 None => None,
85 };
85 };
86
86
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+
87 // TODO: add support for Diagnostic.data
105 // TODO: add support for Diagnostic.data
88 lsp::Diagnostic::new(
106 lsp::Diagnostic::new(
89 range_to_lsp_range(doc, range, offset_encoding),
107 range_to_lsp_range(doc, range, offset_encoding),
90 severity,
108 severity,
91 code,
109 code,
92− None,
110+ diag.source.clone(),
93 diag.message.to_owned(),
111 diag.message.to_owned(),
94 None,
112 None,
95− None,
113+ tags,
96 )
114 )
97 }
115 }
98
116
helix-term/src/application.rs+17−2
@@ -2,7 +2,7 @@ use arc_swap::{access::Map, ArcSwap};
2use futures_util::Stream;
2use futures_util::Stream;
3use helix_core::{
3use helix_core::{
4 config::{default_syntax_loader, user_syntax_loader},
4 config::{default_syntax_loader, user_syntax_loader},
5− diagnostic::NumberOrString,
5+ diagnostic::{DiagnosticTag, NumberOrString},
6 pos_at_coords, syntax, Selection,
6 pos_at_coords, syntax, Selection,
7};
7};
8use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
8use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
@@ -605,13 +605,28 @@ impl Application {
605 None => None,
605 None => None,
606 };
606 };
607
607
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+
608 Some(Diagnostic {
622 Some(Diagnostic {
609 range: Range { start, end },
623 range: Range { start, end },
610 line: diagnostic.range.start.line as usize,
624 line: diagnostic.range.start.line as usize,
611 message: diagnostic.message.clone(),
625 message: diagnostic.message.clone(),
612 severity,
626 severity,
613 code,
627 code,
614− // source
628+ tags,
629+ source: diagnostic.source.clone()
615 })
630 })
616 })
631 })
617 .collect();
632 .collect();