Skip to content

Commit 8d960b7

Browse files
erasinthomasskk
authored andcommitted
Suport diagnostic code (helix-editor#3096)
* add code for diagnostic. This PR provides a solution to resolve helix-editor#2994. missing Code Actions for lsp * remote unused import
1 parent fd8bbbd commit 8d960b7

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

helix-core/src/diagnostic.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ pub struct Range {
2323
pub end: usize,
2424
}
2525

26+
#[derive(Debug, Eq, Hash, PartialEq, Clone, Deserialize, Serialize)]
27+
pub enum NumberOrString {
28+
Number(i32),
29+
String(String),
30+
}
31+
2632
/// Corresponds to [`lsp_types::Diagnostic`](https://docs.rs/lsp-types/0.91.0/lsp_types/struct.Diagnostic.html)
2733
#[derive(Debug, Clone)]
2834
pub struct Diagnostic {
2935
pub range: Range,
3036
pub line: usize,
3137
pub message: String,
3238
pub severity: Option<Severity>,
39+
pub code: Option<NumberOrString>,
3340
}

helix-lsp/src/lib.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub enum OffsetEncoding {
5858

5959
pub mod util {
6060
use super::*;
61-
use helix_core::{Range, Rope, Transaction};
61+
use helix_core::{diagnostic::NumberOrString, Range, Rope, Transaction};
6262

6363
/// Converts a diagnostic in the document to [`lsp::Diagnostic`].
6464
///
@@ -78,11 +78,19 @@ pub mod util {
7878
Error => lsp::DiagnosticSeverity::ERROR,
7979
});
8080

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+
8189
// TODO: add support for Diagnostic.data
8290
lsp::Diagnostic::new(
8391
range_to_lsp_range(doc, range, offset_encoding),
8492
severity,
85-
None,
93+
code,
8694
None,
8795
diag.message.to_owned(),
8896
None,

helix-term/src/application.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use arc_swap::{access::Map, ArcSwap};
22
use futures_util::Stream;
33
use helix_core::{
44
config::{default_syntax_loader, user_syntax_loader},
5+
diagnostic::NumberOrString,
56
pos_at_coords, syntax, Selection,
67
};
78
use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
@@ -556,12 +557,24 @@ impl Application {
556557
}
557558
};
558559

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+
559572
Some(Diagnostic {
560573
range: Range { start, end },
561574
line: diagnostic.range.start.line as usize,
562575
message: diagnostic.message.clone(),
563576
severity,
564-
// code
577+
code,
565578
// source
566579
})
567580
})

0 commit comments

Comments
 (0)