From 93342f15badc6e7a3c213e27979b2ff31e0b393e Mon Sep 17 00:00:00 2001 From: Iordanis Petkakis Date: Sun, 21 Jan 2024 21:41:11 +0200 Subject: [PATCH] feat(toggle): use `vim.diagnostic.is_disabled` when available (#2217) * feat(toggle-diagnostics): change logic based on `vim.diagnostic.is_disabled` After discussion in #2215, I thought maybe it would be beneficial if we could change the logic of the `toggle-diagnostics` function based on if the user has disabled diagnostics in his own configuration. * feat(toggle-diagnostics): revert to `enable` instead of `status` * fix(toggle): use vim.diagnostics enabled state when possible --------- Co-authored-by: Folke Lemaitre --- lua/lazyvim/util/toggle.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lua/lazyvim/util/toggle.lua b/lua/lazyvim/util/toggle.lua index db41c825..409556d1 100644 --- a/lua/lazyvim/util/toggle.lua +++ b/lua/lazyvim/util/toggle.lua @@ -43,7 +43,13 @@ end local enabled = true function M.diagnostics() + -- if this Neovim version supports checking if diagnostics are enabled + -- then use that for the current state + if vim.diagnostic.is_disabled then + enabled = not vim.diagnostic.is_disabled() + end enabled = not enabled + if enabled then vim.diagnostic.enable() Util.info("Enabled diagnostics", { title = "Diagnostics" })