From 0dce39e0df064a564bab0f4eba68285ff21ff9d8 Mon Sep 17 00:00:00 2001 From: Nikita Revenco <154856872+NikitaRevenco@users.noreply.github.com> Date: Fri, 6 Dec 2024 12:51:55 +0000 Subject: [PATCH] feat: add command to toggle diagnostics does not work --- helix-term/src/commands/typed.rs | 25 +++++++++++++++++++++++++ helix-view/src/editor.rs | 7 +++++++ helix-view/src/handlers/diagnostics.rs | 3 +++ 3 files changed, 35 insertions(+) diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 49864abb..e53a02c3 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -1928,6 +1928,24 @@ fn set_option( Ok(()) } +fn toggle_diagnostics( + cx: &mut compositor::Context, + args: &[Cow], + event: PromptEvent, +) -> anyhow::Result<()> { + if event != PromptEvent::Validate { + return Ok(()); + } + + ensure!(args.is_empty(), ":toggle-diagnostics takes no arguments"); + + let (view, _) = current!(cx.editor); + + view.diagnostics_handler.toggle_diagnostics(); + + Ok(()) +} + /// Toggle boolean config option at runtime. Access nested values by dot /// syntax, for example to toggle smart case search, use `:toggle search.smart- /// case`. @@ -3149,6 +3167,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ fun: read, signature: CommandSignature::positional(&[completers::filename]), }, + TypableCommand { + name: "toggle-diagnostics", + aliases: &["td"], + doc: "Toggle Diagnostics", + fun: toggle_diagnostics, + signature: CommandSignature::all(completers::register) + } ]; pub static TYPABLE_COMMAND_MAP: Lazy> = diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index aa9a1153..e3e21c06 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -1049,6 +1049,8 @@ pub struct Editor { pub debugger_events: SelectAll>, pub breakpoints: HashMap>, + pub show_diagnostics: bool, + pub syn_loader: Arc>, pub theme_loader: Arc, /// last_theme is used for theme previews. We store the current theme here, @@ -1195,6 +1197,7 @@ impl Editor { breakpoints: HashMap::new(), syn_loader, theme_loader, + show_diagnostics: true, last_theme: None, last_selection: None, registers: Registers::new(Box::new(arc_swap::access::Map::new( @@ -1328,6 +1331,10 @@ impl Editor { self.set_theme_impl(theme, ThemeAction::Set); } + pub fn toggle_diagnostics(&mut self) { + self.show_diagnostics = !self.show_diagnostics; + } + fn set_theme_impl(&mut self, theme: Theme, preview: ThemeAction) { // `ui.selection` is the only scope required to be able to render a theme. if theme.find_scope_index_exact("ui.selection").is_none() { diff --git a/helix-view/src/handlers/diagnostics.rs b/helix-view/src/handlers/diagnostics.rs index 2b8ff632..a0eb04c7 100644 --- a/helix-view/src/handlers/diagnostics.rs +++ b/helix-view/src/handlers/diagnostics.rs @@ -94,6 +94,9 @@ 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