aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/handlers.lua
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2024-11-05 17:34:21 +0000
committerLewis Russell <me@lewisr.dev>2024-11-18 17:09:53 +0000
commit989a37a594649528f28432388c0e7e28e8be2753 (patch)
tree995df7bc856bc61d69d6666d3c569b5bb1a1f905 /runtime/lua/vim/lsp/handlers.lua
parente2ad251c8d01726ecd54d925b5280ab32b448c13 (diff)
downloadrneovim-989a37a594649528f28432388c0e7e28e8be2753.tar.gz
rneovim-989a37a594649528f28432388c0e7e28e8be2753.tar.bz2
rneovim-989a37a594649528f28432388c0e7e28e8be2753.zip
refactor(lsp): fold in dynamic_registration code into the client
Problem: Capability register logic is spread across 3 files. Solution: - Consolidate (and simplify) logic into the client. - Teach client.supports_method about resolve methods
Diffstat (limited to 'runtime/lua/vim/lsp/handlers.lua')
-rw-r--r--runtime/lua/vim/lsp/handlers.lua50
1 files changed, 10 insertions, 40 deletions
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua
index 2b7aefe0e1..5c28d88b38 100644
--- a/runtime/lua/vim/lsp/handlers.lua
+++ b/runtime/lua/vim/lsp/handlers.lua
@@ -122,46 +122,19 @@ end
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#client_registerCapability
--- @param params lsp.RegistrationParams
RSC[ms.client_registerCapability] = function(_, params, ctx)
- local client_id = ctx.client_id
- local client = assert(vim.lsp.get_client_by_id(client_id))
-
- client.dynamic_capabilities:register(params.registrations)
- for bufnr, _ in pairs(client.attached_buffers) do
+ local client = assert(vim.lsp.get_client_by_id(ctx.client_id))
+ client:_register(params.registrations)
+ for bufnr in pairs(client.attached_buffers) do
vim.lsp._set_defaults(client, bufnr)
end
-
- ---@type string[]
- local unsupported = {}
- for _, reg in ipairs(params.registrations) do
- if reg.method == ms.workspace_didChangeWatchedFiles then
- vim.lsp._watchfiles.register(reg, ctx)
- elseif not client.dynamic_capabilities:supports_registration(reg.method) then
- unsupported[#unsupported + 1] = reg.method
- end
- end
- if #unsupported > 0 then
- local warning_tpl = 'The language server %s triggers a registerCapability '
- .. 'handler for %s despite dynamicRegistration set to false. '
- .. 'Report upstream, this warning is harmless'
- local client_name = client and client.name or string.format('id=%d', client_id)
- local warning = string.format(warning_tpl, client_name, table.concat(unsupported, ', '))
- log.warn(warning)
- end
return vim.NIL
end
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#client_unregisterCapability
--- @param params lsp.UnregistrationParams
RSC[ms.client_unregisterCapability] = function(_, params, ctx)
- local client_id = ctx.client_id
- local client = assert(vim.lsp.get_client_by_id(client_id))
- client.dynamic_capabilities:unregister(params.unregisterations)
-
- for _, unreg in ipairs(params.unregisterations) do
- if unreg.method == ms.workspace_didChangeWatchedFiles then
- vim.lsp._watchfiles.unregister(unreg, ctx)
- end
- end
+ local client = assert(vim.lsp.get_client_by_id(ctx.client_id))
+ client:_unregister(params.unregisterations)
return vim.NIL
end
@@ -173,8 +146,7 @@ RSC[ms.workspace_applyEdit] = function(_, params, ctx)
'workspace/applyEdit must be called with `ApplyWorkspaceEditParams`. Server is violating the specification'
)
-- TODO(ashkan) Do something more with label?
- local client_id = ctx.client_id
- local client = assert(vim.lsp.get_client_by_id(client_id))
+ local client = assert(vim.lsp.get_client_by_id(ctx.client_id))
if params.label then
print('Workspace edit', params.label)
end
@@ -196,12 +168,11 @@ end
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_configuration
--- @param params lsp.ConfigurationParams
RSC[ms.workspace_configuration] = function(_, params, ctx)
- local client_id = ctx.client_id
- local client = vim.lsp.get_client_by_id(client_id)
+ local client = vim.lsp.get_client_by_id(ctx.client_id)
if not client then
err_message(
'LSP[',
- client_id,
+ ctx.client_id,
'] client has shut down after sending a workspace/configuration request'
)
return
@@ -229,10 +200,9 @@ end
--- @see # https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_workspaceFolders
RSC[ms.workspace_workspaceFolders] = function(_, _, ctx)
- local client_id = ctx.client_id
- local client = vim.lsp.get_client_by_id(client_id)
+ local client = vim.lsp.get_client_by_id(ctx.client_id)
if not client then
- err_message('LSP[id=', client_id, '] client has shut down after sending the message')
+ err_message('LSP[id=', ctx.client_id, '] client has shut down after sending the message')
return
end
return client.workspace_folders or vim.NIL