From 6000d956f0a3e217c3a0563abef738616feb73e6 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 30 Jul 2017 22:18:19 +0100 Subject: [PATCH] When servers never send an initialize response, but instead just publish diagnostics straight away, handle that as an initialize response --- autoload/ale/lsp.vim | 48 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/autoload/ale/lsp.vim b/autoload/ale/lsp.vim index eb407314..855abb11 100644 --- a/autoload/ale/lsp.vim +++ b/autoload/ale/lsp.vim @@ -156,18 +156,11 @@ function! s:FindProjectWithInitRequestID(conn, init_request_id) abort return {} endfunction -function! s:HandleInitializeResponse(conn, response) abort - let l:request_id = a:response.request_id - let l:project = s:FindProjectWithInitRequestID(a:conn, l:request_id) - - if empty(l:project) - return - endif - - let l:project.initialized = 1 +function! s:MarkProjectAsInitialized(conn, project) abort + let a:project.initialized = 1 " After the server starts, send messages we had queued previously. - for l:message_data in l:project.message_queue + for l:message_data in a:project.message_queue call s:SendMessageData(a:conn, l:message_data) endfor @@ -175,6 +168,39 @@ function! s:HandleInitializeResponse(conn, response) abort let a:conn.message_queue = [] endfunction +function! s:HandleInitializeResponse(conn, response) abort + let l:request_id = a:response.request_id + let l:project = s:FindProjectWithInitRequestID(a:conn, l:request_id) + + if !empty(l:project) + call s:MarkProjectAsInitialized(a:conn, l:project) + endif +endfunction + +function! ale#lsp#HandleOtherInitializeResponses(conn, response) abort + let l:uninitialized_projects = [] + + for [l:key, l:value] in items(a:conn.projects) + if l:value.initialized == 0 + call add(l:uninitialized_projects, [l:key, l:value]) + endif + endfor + + if empty(l:uninitialized_projects) + return + endif + + if get(a:response, 'method', '') ==# 'textDocument/publishDiagnostics' + let l:filename = ale#path#FromURI(a:response.params.uri) + + for [l:dir, l:project] in l:uninitialized_projects + if l:filename[:len(l:dir) - 1] ==# l:dir + call s:MarkProjectAsInitialized(a:conn, l:project) + endif + endfor + endif +endfunction + function! ale#lsp#HandleMessage(conn, message) abort let a:conn.data .= a:message @@ -186,6 +212,8 @@ function! ale#lsp#HandleMessage(conn, message) abort if get(l:response, 'method', '') ==# 'initialize' call s:HandleInitializeResponse(a:conn, l:response) else + call ale#lsp#HandleOtherInitializeResponses(a:conn, l:response) + " Call all of the registered handlers with the response. for l:Callback in a:conn.callback_list call ale#util#GetFunction(l:Callback)(l:response)