Fix #2907 - Handle dictionaries for capabilities

This commit is contained in:
w0rp 2020-08-07 10:54:38 +01:00
parent 667618b399
commit 9bdabce8df
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
2 changed files with 76 additions and 1 deletions

View File

@ -196,14 +196,26 @@ function! s:UpdateCapabilities(conn, capabilities) abort
let a:conn.capabilities.hover = 1
endif
if type(get(a:capabilities, 'hoverProvider')) is v:t_dict
let a:conn.capabilities.hover = 1
endif
if get(a:capabilities, 'referencesProvider') is v:true
let a:conn.capabilities.references = 1
endif
if type(get(a:capabilities, 'referencesProvider')) is v:t_dict
let a:conn.capabilities.references = 1
endif
if get(a:capabilities, 'renameProvider') is v:true
let a:conn.capabilities.rename = 1
endif
if type(get(a:capabilities, 'renameProvider')) is v:t_dict
let a:conn.capabilities.rename = 1
endif
if !empty(get(a:capabilities, 'completionProvider'))
let a:conn.capabilities.completion = 1
endif
@ -220,13 +232,25 @@ function! s:UpdateCapabilities(conn, capabilities) abort
let a:conn.capabilities.definition = 1
endif
if type(get(a:capabilities, 'definitionProvider')) is v:t_dict
let a:conn.capabilities.definition = 1
endif
if get(a:capabilities, 'typeDefinitionProvider') is v:true
let a:conn.capabilities.typeDefinition = 1
endif
if type(get(a:capabilities, 'typeDefinitionProvider')) is v:t_dict
let a:conn.capabilities.typeDefinition = 1
endif
if get(a:capabilities, 'workspaceSymbolProvider') is v:true
let a:conn.capabilities.symbol_search = 1
endif
if type(get(a:capabilities, 'workspaceSymbolProvider')) is v:t_dict
let a:conn.capabilities.symbol_search = 1
endif
endfunction
" Update a connection's configuration dictionary and notify LSP servers

View File

@ -131,7 +131,7 @@ Execute(Disabled capabilities should be recognised correctly):
\ },
\ 'definitionProvider': v:false,
\ 'experimental': {},
\ 'documentHighlightProvider': v:true
\ 'documentHighlightProvider': v:true,
\ },
\ },
\})
@ -150,6 +150,57 @@ Execute(Disabled capabilities should be recognised correctly):
\ b:conn.capabilities
AssertEqual [[1, 'initialized', {}]], g:message_list
Execute(Capabilities should be enabled when send as Dictionaries):
call ale#lsp#HandleInitResponse(b:conn, {
\ 'jsonrpc': '2.0',
\ 'id': 1,
\ 'result': {
\ 'capabilities': {
\ 'renameProvider': {},
\ 'executeCommandProvider': {
\ 'commands': [],
\ },
\ 'hoverProvider': {},
\ 'documentSymbolProvider': v:true,
\ 'documentRangeFormattingProvider': v:true,
\ 'codeLensProvider': {
\ 'resolveProvider': v:false
\ },
\ 'completionProvider': {
\ 'triggerCharacters': ['.'],
\ 'resolveProvider': v:false
\ },
\ 'referencesProvider': {},
\ 'textDocumentSync': 2,
\ 'documentFormattingProvider': v:true,
\ 'codeActionProvider': v:true,
\ 'signatureHelpProvider': {
\ 'triggerCharacters': ['(', ','],
\ },
\ 'definitionProvider': {},
\ 'typeDefinitionProvider': {},
\ 'experimental': {},
\ 'documentHighlightProvider': v:true,
\ 'workspaceSymbolProvider': {}
\ },
\ },
\})
AssertEqual 1, b:conn.initialized
AssertEqual
\ {
\ 'completion_trigger_characters': ['.'],
\ 'completion': 1,
\ 'references': 1,
\ 'hover': 1,
\ 'definition': 1,
\ 'typeDefinition': 1,
\ 'symbol_search': 1,
\ 'rename': 1,
\ },
\ b:conn.capabilities
AssertEqual [[1, 'initialized', {}]], g:message_list
Execute(Results that are not dictionaries should be handled correctly):
call ale#lsp#HandleInitResponse(b:conn, {
\ 'jsonrpc': '2.0',