mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	refactor(lsp): remove _resolve_capabilities_compat (#22628)
This commit is contained in:
		| @@ -854,7 +854,6 @@ function protocol.make_client_capabilities() | |||||||
|   } |   } | ||||||
| end | end | ||||||
|  |  | ||||||
| local if_nil = vim.F.if_nil |  | ||||||
| --- Creates a normalized object describing LSP server capabilities. | --- Creates a normalized object describing LSP server capabilities. | ||||||
| ---@param server_capabilities table Table of capabilities supported by the server | ---@param server_capabilities table Table of capabilities supported by the server | ||||||
| ---@return table Normalized table of capabilities | ---@return table Normalized table of capabilities | ||||||
| @@ -892,178 +891,5 @@ function protocol.resolve_capabilities(server_capabilities) | |||||||
|   return server_capabilities |   return server_capabilities | ||||||
| end | end | ||||||
|  |  | ||||||
| ---@private |  | ||||||
| --- Creates a normalized object describing LSP server capabilities. |  | ||||||
| -- @deprecated access resolved_capabilities instead |  | ||||||
| ---@param server_capabilities table Table of capabilities supported by the server |  | ||||||
| ---@return table Normalized table of capabilities |  | ||||||
| function protocol._resolve_capabilities_compat(server_capabilities) |  | ||||||
|   local general_properties = {} |  | ||||||
|   local text_document_sync_properties |  | ||||||
|   do |  | ||||||
|     local TextDocumentSyncKind = protocol.TextDocumentSyncKind |  | ||||||
|     local textDocumentSync = server_capabilities.textDocumentSync |  | ||||||
|     if textDocumentSync == nil then |  | ||||||
|       -- Defaults if omitted. |  | ||||||
|       text_document_sync_properties = { |  | ||||||
|         text_document_open_close = false, |  | ||||||
|         text_document_did_change = TextDocumentSyncKind.None, |  | ||||||
|         --        text_document_did_change = false; |  | ||||||
|         text_document_will_save = false, |  | ||||||
|         text_document_will_save_wait_until = false, |  | ||||||
|         text_document_save = false, |  | ||||||
|         text_document_save_include_text = false, |  | ||||||
|       } |  | ||||||
|     elseif type(textDocumentSync) == 'number' then |  | ||||||
|       -- Backwards compatibility |  | ||||||
|       if not TextDocumentSyncKind[textDocumentSync] then |  | ||||||
|         return nil, 'Invalid server TextDocumentSyncKind for textDocumentSync' |  | ||||||
|       end |  | ||||||
|       text_document_sync_properties = { |  | ||||||
|         text_document_open_close = true, |  | ||||||
|         text_document_did_change = textDocumentSync, |  | ||||||
|         text_document_will_save = false, |  | ||||||
|         text_document_will_save_wait_until = false, |  | ||||||
|         text_document_save = true, |  | ||||||
|         text_document_save_include_text = false, |  | ||||||
|       } |  | ||||||
|     elseif type(textDocumentSync) == 'table' then |  | ||||||
|       text_document_sync_properties = { |  | ||||||
|         text_document_open_close = if_nil(textDocumentSync.openClose, false), |  | ||||||
|         text_document_did_change = if_nil(textDocumentSync.change, TextDocumentSyncKind.None), |  | ||||||
|         text_document_will_save = if_nil(textDocumentSync.willSave, true), |  | ||||||
|         text_document_will_save_wait_until = if_nil(textDocumentSync.willSaveWaitUntil, true), |  | ||||||
|         text_document_save = if_nil(textDocumentSync.save, false), |  | ||||||
|         text_document_save_include_text = if_nil( |  | ||||||
|           type(textDocumentSync.save) == 'table' and textDocumentSync.save.includeText, |  | ||||||
|           false |  | ||||||
|         ), |  | ||||||
|       } |  | ||||||
|     else |  | ||||||
|       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 |  | ||||||
|   general_properties.document_highlight = server_capabilities.documentHighlightProvider or false |  | ||||||
|   general_properties.document_symbol = server_capabilities.documentSymbolProvider or false |  | ||||||
|   general_properties.workspace_symbol = server_capabilities.workspaceSymbolProvider or false |  | ||||||
|   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.codeLensProvider == nil then |  | ||||||
|     general_properties.code_lens = false |  | ||||||
|     general_properties.code_lens_resolve = false |  | ||||||
|   elseif type(server_capabilities.codeLensProvider) == 'table' then |  | ||||||
|     general_properties.code_lens = true |  | ||||||
|     general_properties.code_lens_resolve = server_capabilities.codeLensProvider.resolveProvider |  | ||||||
|       or false |  | ||||||
|   else |  | ||||||
|     error('The server sent invalid codeLensProvider') |  | ||||||
|   end |  | ||||||
|  |  | ||||||
|   if server_capabilities.codeActionProvider == nil then |  | ||||||
|     general_properties.code_action = false |  | ||||||
|   elseif |  | ||||||
|     type(server_capabilities.codeActionProvider) == 'boolean' |  | ||||||
|     or type(server_capabilities.codeActionProvider) == 'table' |  | ||||||
|   then |  | ||||||
|     general_properties.code_action = server_capabilities.codeActionProvider |  | ||||||
|   else |  | ||||||
|     error('The server sent invalid codeActionProvider') |  | ||||||
|   end |  | ||||||
|  |  | ||||||
|   if server_capabilities.declarationProvider == nil then |  | ||||||
|     general_properties.declaration = false |  | ||||||
|   elseif type(server_capabilities.declarationProvider) == 'boolean' then |  | ||||||
|     general_properties.declaration = server_capabilities.declarationProvider |  | ||||||
|   elseif type(server_capabilities.declarationProvider) == 'table' then |  | ||||||
|     general_properties.declaration = server_capabilities.declarationProvider |  | ||||||
|   else |  | ||||||
|     error('The server sent invalid declarationProvider') |  | ||||||
|   end |  | ||||||
|  |  | ||||||
|   if server_capabilities.typeDefinitionProvider == nil then |  | ||||||
|     general_properties.type_definition = false |  | ||||||
|   elseif type(server_capabilities.typeDefinitionProvider) == 'boolean' then |  | ||||||
|     general_properties.type_definition = server_capabilities.typeDefinitionProvider |  | ||||||
|   elseif type(server_capabilities.typeDefinitionProvider) == 'table' then |  | ||||||
|     general_properties.type_definition = server_capabilities.typeDefinitionProvider |  | ||||||
|   else |  | ||||||
|     error('The server sent invalid typeDefinitionProvider') |  | ||||||
|   end |  | ||||||
|  |  | ||||||
|   if server_capabilities.implementationProvider == nil then |  | ||||||
|     general_properties.implementation = false |  | ||||||
|   elseif type(server_capabilities.implementationProvider) == 'boolean' then |  | ||||||
|     general_properties.implementation = server_capabilities.implementationProvider |  | ||||||
|   elseif type(server_capabilities.implementationProvider) == 'table' then |  | ||||||
|     general_properties.implementation = server_capabilities.implementationProvider |  | ||||||
|   else |  | ||||||
|     error('The server sent invalid implementationProvider') |  | ||||||
|   end |  | ||||||
|  |  | ||||||
|   local workspace = server_capabilities.workspace |  | ||||||
|   local workspace_properties = {} |  | ||||||
|   if workspace == nil or workspace.workspaceFolders == nil then |  | ||||||
|     -- Defaults if omitted. |  | ||||||
|     workspace_properties = { |  | ||||||
|       workspace_folder_properties = { |  | ||||||
|         supported = false, |  | ||||||
|         changeNotifications = false, |  | ||||||
|       }, |  | ||||||
|     } |  | ||||||
|   elseif type(workspace.workspaceFolders) == 'table' then |  | ||||||
|     workspace_properties = { |  | ||||||
|       workspace_folder_properties = { |  | ||||||
|         supported = if_nil(workspace.workspaceFolders.supported, false), |  | ||||||
|         changeNotifications = if_nil(workspace.workspaceFolders.changeNotifications, false), |  | ||||||
|       }, |  | ||||||
|     } |  | ||||||
|   else |  | ||||||
|     error('The server sent invalid workspace') |  | ||||||
|   end |  | ||||||
|  |  | ||||||
|   local signature_help_properties |  | ||||||
|   if server_capabilities.signatureHelpProvider == nil then |  | ||||||
|     signature_help_properties = { |  | ||||||
|       signature_help = false, |  | ||||||
|       signature_help_trigger_characters = {}, |  | ||||||
|     } |  | ||||||
|   elseif type(server_capabilities.signatureHelpProvider) == 'table' then |  | ||||||
|     signature_help_properties = { |  | ||||||
|       signature_help = true, |  | ||||||
|       -- The characters that trigger signature help automatically. |  | ||||||
|       signature_help_trigger_characters = server_capabilities.signatureHelpProvider.triggerCharacters |  | ||||||
|         or {}, |  | ||||||
|     } |  | ||||||
|   else |  | ||||||
|     error('The server sent invalid signatureHelpProvider') |  | ||||||
|   end |  | ||||||
|  |  | ||||||
|   local capabilities = vim.tbl_extend( |  | ||||||
|     'error', |  | ||||||
|     text_document_sync_properties, |  | ||||||
|     signature_help_properties, |  | ||||||
|     workspace_properties, |  | ||||||
|     general_properties |  | ||||||
|   ) |  | ||||||
|  |  | ||||||
|   return capabilities |  | ||||||
| end |  | ||||||
|  |  | ||||||
| return protocol | return protocol | ||||||
| -- vim:sw=2 ts=2 et | -- vim:sw=2 ts=2 et | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Raphael
					Raphael