From c012f859597c4ba3e54dd26372351098a25379cd Mon Sep 17 00:00:00 2001 From: Iordanis Petkakis <12776461+dpetka2001@users.noreply.github.com> Date: Sat, 31 Aug 2024 10:44:52 +0300 Subject: [PATCH] fix(toggle): make `diagnostics` compatible with nvim-0.9.5 (#4205) ## Description This makes `toggle.diagnostics` compatible with Neovim 0.9.5 (though not sure about the metatable callables, since `set` there accepts a boolean from `get` state). Please make whatever changes you deem necessary or disregard as a whole for a better approach I haven't been able to think of. ## Related Issue(s) Fixes #4203 ## Screenshots ## Checklist - [x] I've read the [CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md) guidelines. --- lua/lazyvim/util/toggle.lua | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/lua/lazyvim/util/toggle.lua b/lua/lazyvim/util/toggle.lua index 4e0ba494..2bf13934 100644 --- a/lua/lazyvim/util/toggle.lua +++ b/lua/lazyvim/util/toggle.lua @@ -127,9 +127,32 @@ M.number = M.wrap({ M.diagnostics = M.wrap({ name = "Diagnostics", get = function() - return vim.diagnostic.is_enabled and vim.diagnostic.is_enabled() + local enabled + if vim.diagnostic.is_enabled then + enabled = vim.diagnostic.is_enabled() + else + enabled = not vim.diagnostic.is_disabled() + end + return enabled + end, + set = function() + local enabled + if vim.diagnostic.is_enabled then + enabled = vim.diagnostic.is_enabled() + else + enabled = not vim.diagnostic.is_disabled() + end + enabled = not enabled + if vim.fn.has("nvim-0.10") == 0 then + if enabled then + pcall(vim.diagnostic.enable) + else + vim.diagnostic.disable() + end + else + vim.diagnostic.enable(enabled) + end end, - set = vim.diagnostic.enable, }) M.inlay_hints = M.wrap({