lsp: only send buf requests to servers that support the request (#12764)

Refactors how required capabilities are detected and validated, and make
sure requests are only sent to clients that support it (and only fail if
no clients support the provided method).

The validation happens at the buf_request level, because we assume that
if someone is sending the request directly through the client, they know
what they're doing. Also, let unknown methods go through.

This is extracted from #12518 and closes #12755.

Co-authored-by: francisco souza <fsouza@users.noreply.github.com>
This commit is contained in:
francisco souza
2020-10-25 00:28:15 -04:00
committed by GitHub
parent b59b8dd5b5
commit 6312792d8a
4 changed files with 160 additions and 33 deletions

View File

@@ -703,6 +703,10 @@ function protocol.make_client_capabilities()
};
hierarchicalDocumentSymbolSupport = true;
};
rename = {
dynamicRegistration = false;
prepareSupport = true;
};
};
workspace = {
symbol = {
@@ -914,6 +918,7 @@ function protocol.resolve_capabilities(server_capabilities)
return nil, string.format("Invalid type for textDocumentSync: %q", type(textDocumentSync))
end
end
general_properties.completion = server_capabilities.completionProvider ~= nil
general_properties.hover = server_capabilities.hoverProvider or false
general_properties.goto_definition = server_capabilities.definitionProvider or false
general_properties.find_references = server_capabilities.referencesProvider or false
@@ -923,6 +928,15 @@ function protocol.resolve_capabilities(server_capabilities)
general_properties.document_formatting = server_capabilities.documentFormattingProvider or false
general_properties.document_range_formatting = server_capabilities.documentRangeFormattingProvider or false
general_properties.call_hierarchy = server_capabilities.callHierarchyProvider or false
general_properties.execute_command = server_capabilities.executeCommandProvider ~= nil
if server_capabilities.renameProvider == nil then
general_properties.rename = false
elseif type(server_capabilities.renameProvider) == 'boolean' then
general_properties.rename = server_capabilities.renameProvider
else
general_properties.rename = true
end
if server_capabilities.codeActionProvider == nil then
general_properties.code_action = false