From a1a2cce23e0a0bea2694fbfc5434a0204328d22c Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Fri, 6 Dec 2024 13:42:21 +0000 Subject: [PATCH] feat: add `:toggle-diagnostics` command to hide diagnostics --- helix-term/src/commands/typed.rs | 4 +-- helix-term/src/ui/editor.rs | 32 ++++++++++++------- .../src/ui/text_decorations/diagnostics.rs | 1 + helix-view/src/handlers/diagnostics.rs | 8 +++-- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index e53a02c3..dcb78240 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -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(()) } diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 5179be4f..fd86fe4e 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -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); } diff --git a/helix-term/src/ui/text_decorations/diagnostics.rs b/helix-term/src/ui/text_decorations/diagnostics.rs index fb82bcf5..2d1ad5e5 100644 --- a/helix-term/src/ui/text_decorations/diagnostics.rs +++ b/helix-term/src/ui/text_decorations/diagnostics.rs @@ -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) { let severity = diag.severity(); let (sym, sym_severity) = if let Some(next_severity) = next_severity { diff --git a/helix-view/src/handlers/diagnostics.rs b/helix-view/src/handlers/diagnostics.rs index a0eb04c7..cb743b44 100644 --- a/helix-view/src/handlers/diagnostics.rs +++ b/helix-view/src/handlers/diagnostics.rs @@ -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;