Suport diagnostic code (#3096)
* add code for diagnostic. This PR provides a solution to resolve #2994. missing Code Actions for lsp * remote unused import
This commit is contained in:
parent
4f21f430e4
commit
42115d02bc
3 changed files with 31 additions and 3 deletions
|
@ -23,6 +23,12 @@ pub struct Range {
|
||||||
pub end: usize,
|
pub end: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, Hash, PartialEq, Clone, Deserialize, Serialize)]
|
||||||
|
pub enum NumberOrString {
|
||||||
|
Number(i32),
|
||||||
|
String(String),
|
||||||
|
}
|
||||||
|
|
||||||
/// Corresponds to [`lsp_types::Diagnostic`](https://docs.rs/lsp-types/0.91.0/lsp_types/struct.Diagnostic.html)
|
/// Corresponds to [`lsp_types::Diagnostic`](https://docs.rs/lsp-types/0.91.0/lsp_types/struct.Diagnostic.html)
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Diagnostic {
|
pub struct Diagnostic {
|
||||||
|
@ -30,4 +36,5 @@ pub struct Diagnostic {
|
||||||
pub line: usize,
|
pub line: usize,
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub severity: Option<Severity>,
|
pub severity: Option<Severity>,
|
||||||
|
pub code: Option<NumberOrString>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ pub enum OffsetEncoding {
|
||||||
|
|
||||||
pub mod util {
|
pub mod util {
|
||||||
use super::*;
|
use super::*;
|
||||||
use helix_core::{Range, Rope, Transaction};
|
use helix_core::{diagnostic::NumberOrString, Range, Rope, Transaction};
|
||||||
|
|
||||||
/// Converts a diagnostic in the document to [`lsp::Diagnostic`].
|
/// Converts a diagnostic in the document to [`lsp::Diagnostic`].
|
||||||
///
|
///
|
||||||
|
@ -78,11 +78,19 @@ pub mod util {
|
||||||
Error => lsp::DiagnosticSeverity::ERROR,
|
Error => lsp::DiagnosticSeverity::ERROR,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let code = match diag.code.clone() {
|
||||||
|
Some(x) => match x {
|
||||||
|
NumberOrString::Number(x) => Some(lsp::NumberOrString::Number(x)),
|
||||||
|
NumberOrString::String(x) => Some(lsp::NumberOrString::String(x)),
|
||||||
|
},
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
// TODO: add support for Diagnostic.data
|
// TODO: add support for Diagnostic.data
|
||||||
lsp::Diagnostic::new(
|
lsp::Diagnostic::new(
|
||||||
range_to_lsp_range(doc, range, offset_encoding),
|
range_to_lsp_range(doc, range, offset_encoding),
|
||||||
severity,
|
severity,
|
||||||
None,
|
code,
|
||||||
None,
|
None,
|
||||||
diag.message.to_owned(),
|
diag.message.to_owned(),
|
||||||
None,
|
None,
|
||||||
|
|
|
@ -2,6 +2,7 @@ use arc_swap::{access::Map, ArcSwap};
|
||||||
use futures_util::Stream;
|
use futures_util::Stream;
|
||||||
use helix_core::{
|
use helix_core::{
|
||||||
config::{default_syntax_loader, user_syntax_loader},
|
config::{default_syntax_loader, user_syntax_loader},
|
||||||
|
diagnostic::NumberOrString,
|
||||||
pos_at_coords, syntax, Selection,
|
pos_at_coords, syntax, Selection,
|
||||||
};
|
};
|
||||||
use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
|
use helix_lsp::{lsp, util::lsp_pos_to_pos, LspProgressMap};
|
||||||
|
@ -556,12 +557,24 @@ impl Application {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let code = match diagnostic.code.clone() {
|
||||||
|
Some(x) => match x {
|
||||||
|
lsp::NumberOrString::Number(x) => {
|
||||||
|
Some(NumberOrString::Number(x))
|
||||||
|
}
|
||||||
|
lsp::NumberOrString::String(x) => {
|
||||||
|
Some(NumberOrString::String(x))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => None,
|
||||||
|
};
|
||||||
|
|
||||||
Some(Diagnostic {
|
Some(Diagnostic {
|
||||||
range: Range { start, end },
|
range: Range { start, end },
|
||||||
line: diagnostic.range.start.line as usize,
|
line: diagnostic.range.start.line as usize,
|
||||||
message: diagnostic.message.clone(),
|
message: diagnostic.message.clone(),
|
||||||
severity,
|
severity,
|
||||||
// code
|
code,
|
||||||
// source
|
// source
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue