summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2018-07-19 21:15:05 +0100
committerw0rp <devw0rp@gmail.com>2018-07-19 21:15:05 +0100
commit61a5880747128dbf988a076e190ccb346500b5ff (patch)
tree898fd4fa980e30e475ea800f43c29cedc92fca2e /autoload
parent27f1915745d22a2d3831b3431a498d3ef674648c (diff)
downloadale-61a5880747128dbf988a076e190ccb346500b5ff.zip
Capture server capabilities from LSP servers
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/lsp.vim48
1 files changed, 48 insertions, 0 deletions
diff --git a/autoload/ale/lsp.vim b/autoload/ale/lsp.vim
index e44b5bc3..1dac3ab1 100644
--- a/autoload/ale/lsp.vim
+++ b/autoload/ale/lsp.vim
@@ -15,6 +15,8 @@ function! ale#lsp#NewConnection(initialization_options) abort
" open_documents: A Dictionary mapping buffers to b:changedtick, keeping
" track of when documents were opened, and when we last changed them.
" callback_list: A list of callbacks for handling LSP responses.
+ " initialization_options: Options to send to the server.
+ " capabilities: Features the server supports.
let l:conn = {
\ 'id': '',
\ 'data': '',
@@ -22,6 +24,13 @@ function! ale#lsp#NewConnection(initialization_options) abort
\ 'open_documents': {},
\ 'callback_list': [],
\ 'initialization_options': a:initialization_options,
+ \ 'capabilities': {
+ \ 'hover': 0,
+ \ 'references': 0,
+ \ 'completion': 0,
+ \ 'completion_trigger_characters': [],
+ \ 'definition': 0,
+ \ },
\}
call add(s:connections, l:conn)
@@ -44,6 +53,11 @@ function! s:FindConnection(key, value) abort
return {}
endfunction
+" Get the capabilities for a connection, or an empty Dictionary.
+function! ale#lsp#GetConnectionCapabilities(id) abort
+ return get(s:FindConnection('id', a:id), 'capabilities', {})
+endfunction
+
function! ale#lsp#GetNextMessageID() abort
" Use the current ID
let l:id = g:ale_lsp_next_message_id
@@ -185,6 +199,38 @@ function! s:HandleInitializeResponse(conn, response) abort
endif
endfunction
+" Update capabilities from the server, so we know which features the server
+" supports.
+function! s:UpdateCapabilities(conn, capabilities) abort
+ if type(a:capabilities) != type({})
+ return
+ endif
+
+ if get(a:capabilities, 'hoverProvider') is v:true
+ let a:conn.capabilities.hover = 1
+ endif
+
+ if get(a:capabilities, 'referencesProvider') is v:true
+ let a:conn.capabilities.references = 1
+ endif
+
+ if !empty(get(a:capabilities, 'completionProvider'))
+ let a:conn.capabilities.completion = 1
+ endif
+
+ if type(get(a:capabilities, 'completionProvider')) is type({})
+ let l:chars = get(a:capabilities.completionProvider, 'triggerCharacters')
+
+ if type(l:chars) is type([])
+ let a:conn.capabilities.completion_trigger_characters = l:chars
+ endif
+ endif
+
+ if get(a:capabilities, 'definitionProvider') is v:true
+ let a:conn.capabilities.definition = 1
+ endif
+endfunction
+
function! ale#lsp#HandleOtherInitializeResponses(conn, response) abort
let l:uninitialized_projects = []
@@ -200,6 +246,8 @@ function! ale#lsp#HandleOtherInitializeResponses(conn, response) abort
if get(a:response, 'method', '') is# ''
if has_key(get(a:response, 'result', {}), 'capabilities')
+ call s:UpdateCapabilities(a:conn, a:response.result.capabilities)
+
for [l:dir, l:project] in l:uninitialized_projects
call s:MarkProjectAsInitialized(a:conn, l:project)
endfor