Track source and tags in diagnostics (#3898)
This commit is contained in:
parent
130793dfd0
commit
64b0745413
3 changed files with 45 additions and 4 deletions
|
@ -29,6 +29,12 @@ pub enum NumberOrString {
|
||||||
String(String),
|
String(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum DiagnosticTag {
|
||||||
|
Unnecessary,
|
||||||
|
Deprecated,
|
||||||
|
}
|
||||||
|
|
||||||
/// 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 {
|
||||||
|
@ -37,4 +43,6 @@ pub struct Diagnostic {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub severity: Option<Severity>,
|
pub severity: Option<Severity>,
|
||||||
pub code: Option<NumberOrString>,
|
pub code: Option<NumberOrString>,
|
||||||
|
pub tags: Option<Vec<DiagnosticTag>>,
|
||||||
|
pub source: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,15 +84,33 @@ pub mod util {
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let tags = if let Some(ref tags) = diag.tags {
|
||||||
|
let new_tags = tags
|
||||||
|
.iter()
|
||||||
|
.map(|tag| match tag {
|
||||||
|
helix_core::diagnostic::DiagnosticTag::Unnecessary => {
|
||||||
|
lsp::DiagnosticTag::UNNECESSARY
|
||||||
|
}
|
||||||
|
helix_core::diagnostic::DiagnosticTag::Deprecated => {
|
||||||
|
lsp::DiagnosticTag::DEPRECATED
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
Some(new_tags)
|
||||||
|
} else {
|
||||||
|
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,
|
||||||
code,
|
code,
|
||||||
None,
|
diag.source.clone(),
|
||||||
diag.message.to_owned(),
|
diag.message.to_owned(),
|
||||||
None,
|
None,
|
||||||
None,
|
tags,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +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,
|
diagnostic::{DiagnosticTag, 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};
|
||||||
|
@ -605,13 +605,28 @@ impl Application {
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let tags = if let Some(ref tags) = diagnostic.tags {
|
||||||
|
let new_tags = tags.iter().filter_map(|tag| {
|
||||||
|
match *tag {
|
||||||
|
lsp::DiagnosticTag::DEPRECATED => Some(DiagnosticTag::Deprecated),
|
||||||
|
lsp::DiagnosticTag::UNNECESSARY => Some(DiagnosticTag::Unnecessary),
|
||||||
|
_ => None
|
||||||
|
}
|
||||||
|
}).collect();
|
||||||
|
|
||||||
|
Some(new_tags)
|
||||||
|
} else {
|
||||||
|
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
|
tags,
|
||||||
|
source: diagnostic.source.clone()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
Loading…
Add table
Reference in a new issue