on master help sign in
Suport diagnostic code (#3096)
42115d0Erasin
helix-core/src/diagnostic.rs+7
@@ -23,6 +23,12 @@ pub struct Range {
23 pub end: usize,
23 pub end: usize,
24}
24}
25
25
26+#[derive(Debug, Eq, Hash, PartialEq, Clone, Deserialize, Serialize)]
27+pub enum NumberOrString {
28+ Number(i32),
29+ String(String),
30+}
31+
26/// Corresponds to [`lsp_types::Diagnostic`](https://docs.rs/lsp-types/0.91.0/lsp_types/struct.Diagnostic.html)
32/// Corresponds to [`lsp_types::Diagnostic`](https://docs.rs/lsp-types/0.91.0/lsp_types/struct.Diagnostic.html)
27#[derive(Debug, Clone)]
33#[derive(Debug, Clone)]
28pub struct Diagnostic {
34pub struct Diagnostic {
@@ -30,4 +36,5 @@ pub struct Diagnostic {
30 pub line: usize,
36 pub line: usize,
31 pub message: String,
37 pub message: String,
32 pub severity: Option<Severity>,
38 pub severity: Option<Severity>,
39+ pub code: Option<NumberOrString>,
33}
40}
helix-lsp/src/lib.rs+10−2
@@ -58,7 +58,7 @@ pub enum OffsetEncoding {
58
58
59pub mod util {
59pub mod util {
60 use super::*;
60 use super::*;
61− use helix_core::{Range, Rope, Transaction};
61+ use helix_core::{diagnostic::NumberOrString, Range, Rope, Transaction};
62
62
63 /// Converts a diagnostic in the document to [`lsp::Diagnostic`].
63 /// Converts a diagnostic in the document to [`lsp::Diagnostic`].
64 ///
64 ///
@@ -78,11 +78,19 @@ pub mod util {
78 Error => lsp::DiagnosticSeverity::ERROR,
78 Error => lsp::DiagnosticSeverity::ERROR,
79 });
79 });
80
80
81+ let code = match diag.code.clone() {
82+ Some(x) => match x {
83+ NumberOrString::Number(x) => Some(lsp::NumberOrString::Number(x)),
84+ NumberOrString::String(x) => Some(lsp::NumberOrString::String(x)),
85+ },
86+ None => None,
87+ };
88+
81 // TODO: add support for Diagnostic.data
89 // TODO: add support for Diagnostic.data
82 lsp::Diagnostic::new(
90 lsp::Diagnostic::new(
83 range_to_lsp_range(doc, range, offset_encoding),
91 range_to_lsp_range(doc, range, offset_encoding),
84 severity,
92 severity,
85− None,
93+ code,
86 None,
94 None,
87 diag.message.to_owned(),
95 diag.message.to_owned(),
88 None,
96 None,
helix-term/src/application.rs+14−1
@@ -2,6 +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 pos_at_coords, syntax, Selection,
6 pos_at_coords, syntax, Selection,
6};
7};
7use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
8use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
@@ -556,12 +557,24 @@ impl Application {
556 }
557 }
557 };
558 };
558
559
560+ let code = match diagnostic.code.clone() {
561+ Some(x) => match x {
562+ lsp::NumberOrString::Number(x) => {
563+ Some(NumberOrString::Number(x))
564+ }
565+ lsp::NumberOrString::String(x) => {
566+ Some(NumberOrString::String(x))
567+ }
568+ },
569+ None => None,
570+ };
571+
559 Some(Diagnostic {
572 Some(Diagnostic {
560 range: Range { start, end },
573 range: Range { start, end },
561 line: diagnostic.range.start.line as usize,
574 line: diagnostic.range.start.line as usize,
562 message: diagnostic.message.clone(),
575 message: diagnostic.message.clone(),
563 severity,
576 severity,
564− // code
577+ code,
565 // source
578 // source
566 })
579 })
567 })
580 })