From 30a950e77f76695740071d773880f186925e8cd9 Mon Sep 17 00:00:00 2001 From: Iordanis Petkakis Date: Sat, 27 Jan 2024 01:07:29 +0200 Subject: [PATCH] fix(toggle-diagnostics): correctly set initial state With the previous implementation of `toggle-diagnostics` in #3cbfeab, if the user had disabled diagnostics, the first toggle call (using the keymap) would again disable diagnostics and the next one would enable them. --- lua/lazyvim/util/toggle.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lua/lazyvim/util/toggle.lua b/lua/lazyvim/util/toggle.lua index 409556d1..11b1c55c 100644 --- a/lua/lazyvim/util/toggle.lua +++ b/lua/lazyvim/util/toggle.lua @@ -41,13 +41,15 @@ function M.number() end end -local enabled = true +local enabled +-- 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() +else + enabled = true +end 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