From d2d30dfabdaacfd53b081354248402c797576482 Mon Sep 17 00:00:00 2001 From: Gregory Anders <8965202+gpanders@users.noreply.github.com> Date: Sun, 17 Oct 2021 08:18:35 -0600 Subject: fix(diagnostic): do not override existing config settings #16043 When using `true` as the value of a configuration option, the option is configured to use default values. For example, if a user configures virtual text to include the source globally (using vim.diagnostic.config) and a specific namespace or producer configures virtual text with `virt_text = true`, the user's global configuration is overriden. Instead, interpret a value of `true` to mean "use existing settings if defined, otherwise use defaults". --- test/functional/lua/diagnostic_spec.lua | 72 +++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'test/functional/lua/diagnostic_spec.lua') diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index a08c8d8681..33469597a1 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -473,6 +473,78 @@ describe('vim.diagnostic', function() end) describe('config()', function() + it('works with global, namespace, and ephemeral options', function() + eq(1, exec_lua [[ + vim.diagnostic.config({ + virtual_text = false, + }) + + vim.diagnostic.config({ + virtual_text = true, + underline = false, + }, diagnostic_ns) + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_error('Some Error', 4, 4, 4, 4), + }) + + return count_extmarks(diagnostic_bufnr, diagnostic_ns) + ]]) + + eq(1, exec_lua [[ + vim.diagnostic.config({ + virtual_text = false, + }) + + vim.diagnostic.config({ + virtual_text = false, + underline = false, + }, diagnostic_ns) + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_error('Some Error', 4, 4, 4, 4), + }, {virtual_text = true}) + + return count_extmarks(diagnostic_bufnr, diagnostic_ns) + ]]) + + eq(0, exec_lua [[ + vim.diagnostic.config({ + virtual_text = false, + }) + + vim.diagnostic.config({ + virtual_text = {severity=vim.diagnostic.severity.ERROR}, + underline = false, + }, diagnostic_ns) + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_warning('Some Warning', 4, 4, 4, 4), + }, {virtual_text = true}) + + return count_extmarks(diagnostic_bufnr, diagnostic_ns) + ]]) + + eq(1, exec_lua [[ + vim.diagnostic.config({ + virtual_text = false, + }) + + vim.diagnostic.config({ + virtual_text = {severity=vim.diagnostic.severity.ERROR}, + underline = false, + }, diagnostic_ns) + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_warning('Some Warning', 4, 4, 4, 4), + }, { + virtual_text = {} -- An empty table uses default values + }) + + return count_extmarks(diagnostic_bufnr, diagnostic_ns) + ]]) + end) + it('can use functions for config values', function() exec_lua [[ vim.diagnostic.config({ -- cgit