feat: add :toggle-diagnostics
command to hide diagnostics
This commit is contained in:
parent
0dce39e0df
commit
a1a2cce23e
4 changed files with 28 additions and 17 deletions
|
@ -1940,8 +1940,8 @@ fn toggle_diagnostics(
|
|||
ensure!(args.is_empty(), ":toggle-diagnostics takes no arguments");
|
||||
|
||||
let (view, _) = current!(cx.editor);
|
||||
|
||||
view.diagnostics_handler.toggle_diagnostics();
|
||||
view.diagnostics_handler.toggle_active();
|
||||
cx.editor.toggle_diagnostics();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -189,19 +189,26 @@ impl EditorView {
|
|||
primary_cursor,
|
||||
});
|
||||
}
|
||||
let width = view.inner_width(doc);
|
||||
let config = doc.config.load();
|
||||
let enable_cursor_line = view
|
||||
.diagnostics_handler
|
||||
.show_cursorline_diagnostics(doc, view.id);
|
||||
let inline_diagnostic_config = config.inline_diagnostics.prepare(width, enable_cursor_line);
|
||||
decorations.add_decoration(InlineDiagnostics::new(
|
||||
doc,
|
||||
theme,
|
||||
primary_cursor,
|
||||
inline_diagnostic_config,
|
||||
config.end_of_line_diagnostics,
|
||||
));
|
||||
|
||||
if editor.show_diagnostics {
|
||||
log::error!("{:#?}", editor.show_diagnostics);
|
||||
let width = view.inner_width(doc);
|
||||
let enable_cursor_line = view
|
||||
.diagnostics_handler
|
||||
.show_cursorline_diagnostics(doc, view.id);
|
||||
let inline_diagnostic_config =
|
||||
config.inline_diagnostics.prepare(width, enable_cursor_line);
|
||||
|
||||
decorations.add_decoration(InlineDiagnostics::new(
|
||||
doc,
|
||||
theme,
|
||||
primary_cursor,
|
||||
inline_diagnostic_config,
|
||||
config.end_of_line_diagnostics,
|
||||
));
|
||||
}
|
||||
|
||||
render_document(
|
||||
surface,
|
||||
inner,
|
||||
|
@ -229,6 +236,7 @@ impl EditorView {
|
|||
|
||||
if config.inline_diagnostics.disabled()
|
||||
&& config.end_of_line_diagnostics == DiagnosticFilter::Disable
|
||||
&& editor.show_diagnostics
|
||||
{
|
||||
Self::render_diagnostics(doc, view, inner, surface, theme);
|
||||
}
|
||||
|
|
|
@ -123,6 +123,7 @@ impl Renderer<'_, '_> {
|
|||
end_col - start_col
|
||||
}
|
||||
|
||||
// need to toggle this
|
||||
fn draw_diagnostic(&mut self, diag: &Diagnostic, col: u16, next_severity: Option<Severity>) {
|
||||
let severity = diag.severity();
|
||||
let (sym, sym_severity) = if let Some(next_severity) = next_severity {
|
||||
|
|
|
@ -94,9 +94,6 @@ impl DiagnosticsHandler {
|
|||
}
|
||||
|
||||
impl DiagnosticsHandler {
|
||||
pub fn toggle_diagnostics(&mut self) {
|
||||
self.active = !self.active;
|
||||
}
|
||||
pub fn immediately_show_diagnostic(&self, doc: &Document, view: ViewId) {
|
||||
self.last_doc.set(doc.id());
|
||||
let cursor_line = doc
|
||||
|
@ -107,6 +104,11 @@ impl DiagnosticsHandler {
|
|||
self.active_generation
|
||||
.store(self.generation.get(), atomic::Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub fn toggle_active(&mut self) {
|
||||
self.active = !self.active;
|
||||
}
|
||||
|
||||
pub fn show_cursorline_diagnostics(&self, doc: &Document, view: ViewId) -> bool {
|
||||
if !self.active {
|
||||
return false;
|
||||
|
|
Loading…
Add table
Reference in a new issue