From fc8af96888f746aeae84660502d2f529a5c2cfc1 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Tue, 11 Jan 2022 16:39:15 -0700 Subject: [PATCH 1/4] fix(diagnostic): resolve nil opts tables In functions which allow opts to be optional, ensure that the value actually resolves to a non-nil value. --- runtime/lua/vim/diagnostic.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index 417b661155..76e19b2de2 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -823,6 +823,7 @@ M.handlers.signs = { } bufnr = get_bufnr(bufnr) + opts = opts or {} if opts.signs and opts.signs.severity then diagnostics = filter_by_severity(opts.signs.severity, diagnostics) @@ -890,6 +891,7 @@ M.handlers.underline = { } bufnr = get_bufnr(bufnr) + opts = opts or {} if opts.underline and opts.underline.severity then diagnostics = filter_by_severity(opts.underline.severity, diagnostics) @@ -942,6 +944,7 @@ M.handlers.virtual_text = { } bufnr = get_bufnr(bufnr) + opts = opts or {} local severity if opts.virtual_text then From 984270c09f628415f99e576c64e93041731a8ba6 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Tue, 11 Jan 2022 16:43:47 -0700 Subject: [PATCH 2/4] fix(diagnostic): allow setting arbitrary config values --- runtime/lua/vim/diagnostic.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index 76e19b2de2..1425de854a 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -611,10 +611,8 @@ function M.config(opts, namespace) t = global_diagnostic_options end - for opt in pairs(global_diagnostic_options) do - if opts[opt] ~= nil then - t[opt] = opts[opt] - end + for k, v in pairs(opts) do + t[k] = v end if namespace then From 8a27205d09405b9b040f0122e2adbd22fc29d498 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Tue, 11 Jan 2022 16:44:07 -0700 Subject: [PATCH 3/4] fix(diagnostic): only set default handler config if unset --- runtime/lua/vim/diagnostic.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index 1425de854a..4bf69a2d39 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -30,7 +30,7 @@ M.handlers = setmetatable({}, { __newindex = function(t, name, handler) vim.validate { handler = {handler, "t" } } rawset(t, name, handler) - if not global_diagnostic_options[name] then + if global_diagnostic_options[name] == nil then global_diagnostic_options[name] = true end end, From c915571b99d7e1ea99e29b103ca2ad37b5974027 Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Tue, 11 Jan 2022 16:44:31 -0700 Subject: [PATCH 4/4] feat(diagnostic): allow retrieving current diagnostic config --- runtime/doc/diagnostic.txt | 5 +++-- runtime/lua/vim/diagnostic.lua | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/runtime/doc/diagnostic.txt b/runtime/doc/diagnostic.txt index bb36fa46f6..19db3158be 100644 --- a/runtime/doc/diagnostic.txt +++ b/runtime/doc/diagnostic.txt @@ -334,8 +334,9 @@ config({opts}, {namespace}) *vim.diagnostic.config()* that returns any of the above. Parameters: ~ - {opts} table Configuration table with the following - keys: + {opts} table|nil When omitted or "nil", retrieve the + current configuration. Otherwise, a + configuration table with the following keys: • underline: (default true) Use underline for diagnostics. Options: • severity: Only underline diagnostics diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index 4bf69a2d39..b4537c2882 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -552,7 +552,8 @@ end --- - `table`: Enable this feature with overrides. Use an empty table to use default values. --- - `function`: Function with signature (namespace, bufnr) that returns any of the above. --- ----@param opts table Configuration table with the following keys: +---@param opts table|nil When omitted or "nil", retrieve the current configuration. Otherwise, a +--- configuration table with the following keys: --- - underline: (default true) Use underline for diagnostics. Options: --- * severity: Only underline diagnostics matching the given severity --- |diagnostic-severity| @@ -599,7 +600,7 @@ end --- global diagnostic options. function M.config(opts, namespace) vim.validate { - opts = { opts, 't' }, + opts = { opts, 't', true }, namespace = { namespace, 'n', true }, } @@ -611,6 +612,11 @@ function M.config(opts, namespace) t = global_diagnostic_options end + if not opts then + -- Return current config + return vim.deepcopy(t) + end + for k, v in pairs(opts) do t[k] = v end