aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/handlers.lua
diff options
context:
space:
mode:
authorJongwook Choi <wookayin@gmail.com>2024-01-14 23:12:54 -0500
committerLewis Russell <me@lewisr.dev>2024-01-16 20:14:17 +0000
commit3973a5e40505422c7ac42692eaecc1ff84f89e7f (patch)
tree7e270515a2e1b89daf690db942ee19871c1f74a9 /runtime/lua/vim/lsp/handlers.lua
parent8f02ae82e203920b472d17e75a61763f3a409a7b (diff)
downloadrneovim-3973a5e40505422c7ac42692eaecc1ff84f89e7f.tar.gz
rneovim-3973a5e40505422c7ac42692eaecc1ff84f89e7f.tar.bz2
rneovim-3973a5e40505422c7ac42692eaecc1ff84f89e7f.zip
refactor(lsp): deprecate `vim.lsp.util.lookup_section`
This function is used only in the `workspace/configuration` handler, and does not warrant a public API because of its confusing return types. The only caller `vim.lsp.handlers["workspace.configuration"]` is also refactored to use `vim.tbl_get()` instead.
Diffstat (limited to 'runtime/lua/vim/lsp/handlers.lua')
-rw-r--r--runtime/lua/vim/lsp/handlers.lua17
1 files changed, 14 insertions, 3 deletions
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua
index daf09b6430..6ed8e1d40f 100644
--- a/runtime/lua/vim/lsp/handlers.lua
+++ b/runtime/lua/vim/lsp/handlers.lua
@@ -170,6 +170,14 @@ M[ms.workspace_applyEdit] = function(_, workspace_edit, ctx)
}
end
+---@param table table e.g., { foo = { bar = "z" } }
+---@param section string indicating the field of the table, e.g., "foo.bar"
+---@return any|nil setting value read from the table, or `nil` not found
+local function lookup_section(table, section)
+ local keys = vim.split(section, '.', { plain = true }) --- @type string[]
+ return vim.tbl_get(table, unpack(keys))
+end
+
--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_configuration
M[ms.workspace_configuration] = function(_, result, ctx)
local client_id = ctx.client_id
@@ -189,10 +197,13 @@ M[ms.workspace_configuration] = function(_, result, ctx)
local response = {}
for _, item in ipairs(result.items) do
if item.section then
- local value = util.lookup_section(client.config.settings, item.section)
+ local value = lookup_section(client.config.settings, item.section)
-- For empty sections with no explicit '' key, return settings as is
- if value == vim.NIL and item.section == '' then
- value = client.config.settings or vim.NIL
+ if value == nil and item.section == '' then
+ value = client.config.settings
+ end
+ if value == nil then
+ value = vim.NIL
end
table.insert(response, value)
end