feat(keymaps): added toggle for diagnostics and conceal

This commit is contained in:
Folke Lemaitre 2023-01-06 23:51:22 +01:00
parent 8174821b71
commit 77672ba3fd
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 29 additions and 1 deletions

View file

@ -71,7 +71,20 @@ function M.float_term(cmd, opts)
end
---@param silent boolean?
function M.toggle(option, silent)
---@param values? {[1]:any, [2]:any}
function M.toggle(option, silent, values)
if values then
if vim.opt_local[option]:get() == values[1] then
vim.opt_local[option] = values[2]
else
vim.opt_local[option] = values[1]
end
return vim.notify(
"Set " .. option .. " to " .. vim.opt_local[option]:get(),
vim.log.levels.INFO,
{ title = "Option" }
)
end
vim.opt_local[option] = not vim.opt_local[option]:get()
if not silent then
vim.notify(
@ -82,4 +95,16 @@ function M.toggle(option, silent)
end
end
local enabled = true
function M.toggle_diagnostics()
enabled = not enabled
if enabled then
vim.diagnostic.enable()
vim.notify("Enabled diagnostics", vim.log.levels.INFO, { title = "Diagnostics" })
else
vim.diagnostic.disable()
vim.notify("Disabled diagnostics", vim.log.levels.INFO, { title = "Diagnostics" })
end
end
return M