fix(lsp): fix lookup of boolean values in workspace/configuration (#18026)

This commit is contained in:
Fredrik Ekre 2022-04-15 11:12:41 +02:00 committed by GitHub
parent 8486c87e58
commit 6160973f36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 4 deletions

View File

@ -141,7 +141,7 @@ M['workspace/configuration'] = function(_, result, ctx)
local response = {} local response = {}
for _, item in ipairs(result.items) do for _, item in ipairs(result.items) do
if item.section then if item.section then
local value = util.lookup_section(client.config.settings, item.section) or vim.NIL local value = util.lookup_section(client.config.settings, item.section)
-- For empty sections with no explicit '' key, return settings as is -- For empty sections with no explicit '' key, return settings as is
if value == vim.NIL and item.section == '' then if value == vim.NIL and item.section == '' then
value = client.config.settings or vim.NIL value = client.config.settings or vim.NIL

View File

@ -1950,8 +1950,8 @@ end
function M.lookup_section(settings, section) function M.lookup_section(settings, section)
for part in vim.gsplit(section, '.', true) do for part in vim.gsplit(section, '.', true) do
settings = settings[part] settings = settings[part]
if not settings then if settings == nil then
return return vim.NIL
end end
end end
return settings return settings

View File

@ -119,8 +119,10 @@ function tests.check_workspace_configuration()
notify('workspace/configuration', { items = { notify('workspace/configuration', { items = {
{ section = "testSetting1" }; { section = "testSetting1" };
{ section = "testSetting2" }; { section = "testSetting2" };
{ section = "test.Setting3" };
{ section = "test.Setting4" };
} }) } })
expect_notification('workspace/configuration', { true; vim.NIL}) expect_notification('workspace/configuration', { true; false; 'nested'; vim.NIL})
notify('shutdown') notify('shutdown')
end; end;
} }

View File

@ -347,6 +347,8 @@ describe('LSP', function()
{NIL, { items = { {NIL, { items = {
{ section = "testSetting1" }; { section = "testSetting1" };
{ section = "testSetting2" }; { section = "testSetting2" };
{ section = "test.Setting3" };
{ section = "test.Setting4" };
}}, { method="workspace/configuration", client_id=1}}; }}, { method="workspace/configuration", client_id=1}};
{NIL, {}, {method="start", client_id=1}}; {NIL, {}, {method="start", client_id=1}};
} }
@ -368,6 +370,7 @@ describe('LSP', function()
client.config.settings = { client.config.settings = {
testSetting1 = true; testSetting1 = true;
testSetting2 = false; testSetting2 = false;
test = {Setting3 = 'nested' };
}]=]) }]=])
end end
if ctx.method == 'workspace/configuration' then if ctx.method == 'workspace/configuration' then