on master help sign in
Suport diagnostic code (#3096)

* add code for diagnostic. This PR provides a solution to resolve #2994. missing Code Actions for lsp * remote unused import

commit42115d02bc9236adf7d1aa81029ca6a12856a160 authorErasin <erasinoo@gmail.com> dateTue 26 Jul 2022, 09:26 (4 years ago) parent4f21f43
3 files changed+31−3
helix-core/src/diagnostic.rs+7 helix-lsp/src/lib.rs+10−2 helix-term/src/application.rs+14−1
helix-core/src/diagnostic.rs+7
@@ -23,6 +23,12 @@ 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)]
2834pub struct Diagnostic {
@@ -30,4 +36,5 @@ pub struct Diagnostic {
3036 pub line: usize,
3137 pub message: String,
3238 pub severity: Option<Severity>,
39+ pub code: Option<NumberOrString>,
3340}
helix-lsp/src/lib.rs+10−2
@@ -58,7 +58,7 @@ pub enum OffsetEncoding {
5858
5959pub 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+14−1
@@ -2,6 +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,
56 pos_at_coords, syntax, Selection,
67};
78use 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 })