mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
feat(lsp): static registration support (#34371)
This commit is contained in:
committed by
GitHub
parent
a5f236291c
commit
d75ffa5934
@@ -554,6 +554,8 @@ function Client:initialize()
|
||||
assert(result.capabilities, "initialize result doesn't contain capabilities")
|
||||
self.server_capabilities = assert(lsp.protocol.resolve_capabilities(self.server_capabilities))
|
||||
|
||||
self:_process_static_registrations()
|
||||
|
||||
if self.server_capabilities.positionEncoding then
|
||||
self.offset_encoding = self.server_capabilities.positionEncoding
|
||||
end
|
||||
@@ -585,6 +587,48 @@ function Client:initialize()
|
||||
end)
|
||||
end
|
||||
|
||||
-- Server capabilities for methods that support static registration.
|
||||
local static_registration_capabilities = {
|
||||
[ms.textDocument_prepareCallHierarchy] = 'callHierarchyProvider',
|
||||
[ms.textDocument_documentColor] = 'colorProvider',
|
||||
[ms.textDocument_declaration] = 'declarationProvider',
|
||||
[ms.textDocument_diagnostic] = 'diagnosticProvider',
|
||||
[ms.textDocument_foldingRange] = 'foldingRangeProvider',
|
||||
[ms.textDocument_implementation] = 'implementationProvider',
|
||||
[ms.textDocument_inlayHint] = 'inlayHintProvider',
|
||||
[ms.textDocument_inlineValue] = 'inlineValueProvider',
|
||||
[ms.textDocument_linkedEditingRange] = 'linkedEditingRangeProvider',
|
||||
[ms.textDocument_moniker] = 'monikerProvider',
|
||||
[ms.textDocument_selectionRange] = 'selectionRangeProvider',
|
||||
[ms.textDocument_semanticTokens_full] = 'semanticTokensProvider',
|
||||
[ms.textDocument_typeDefinition] = 'typeDefinitionProvider',
|
||||
[ms.textDocument_prepareTypeHierarchy] = 'typeHierarchyProvider',
|
||||
}
|
||||
|
||||
--- @private
|
||||
function Client:_process_static_registrations()
|
||||
local static_registrations = {} ---@type lsp.Registration[]
|
||||
|
||||
for method, capability in pairs(static_registration_capabilities) do
|
||||
if
|
||||
vim.tbl_get(self.server_capabilities, capability, 'id')
|
||||
and self:_supports_registration(method)
|
||||
then
|
||||
static_registrations[#static_registrations + 1] = {
|
||||
id = self.server_capabilities[capability].id,
|
||||
method = method,
|
||||
registerOptions = {
|
||||
documentSelector = self.server_capabilities[capability].documentSelector, ---@type lsp.DocumentSelector?
|
||||
},
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
if next(static_registrations) then
|
||||
self:_register_dynamic(static_registrations)
|
||||
end
|
||||
end
|
||||
|
||||
--- @private
|
||||
--- Returns the handler associated with an LSP method.
|
||||
--- Returns the default handler if the user hasn't set a custom one.
|
||||
|
||||
Reference in New Issue
Block a user