fix(util): attempt to concatenate a boolean

If you passed a table of values { false, true } for example, then the
code would attempt to concatenate the raw boolean in Util.info()

Additionally, honor the silent option when explicit values are passed,
and allow passing a single value and don't do anything if already set.
This commit is contained in:
Aron Griffis 2023-07-20 14:36:21 -04:00
parent abaa6d90e4
commit 7ae136d07e

View file

@ -166,16 +166,21 @@ function M.float_term(cmd, opts)
end
---@param silent boolean?
---@param values? {[1]:any, [2]:any}
---@param values? {[1]:any, [2]?:any}
function M.toggle(option, silent, values)
if values then
if vim.opt_local[option]:get() == values[1] then
if values[2] == values[1] or values[2] == nil then
return -- Nothing to do
end
vim.opt_local[option] = values[2]
else
vim.opt_local[option] = values[1]
end
return Util.info("Set " .. option .. " to " .. vim.opt_local[option]:get(), { title = "Option" })
if not silent then
Util.info("Set " .. option .. " to " .. tostring(vim.opt_local[option]:get()), { title = "Option" })
end
else
vim.opt_local[option] = not vim.opt_local[option]:get()
if not silent then
if vim.opt_local[option]:get() then
@ -185,6 +190,7 @@ function M.toggle(option, silent, values)
end
end
end
end
local enabled = true
function M.toggle_diagnostics()