diff options
-rw-r--r-- | autoload/ale/job.vim | 2 | ||||
-rw-r--r-- | autoload/ale/lsp.vim | 32 |
2 files changed, 18 insertions, 16 deletions
diff --git a/autoload/ale/job.vim b/autoload/ale/job.vim index d0572f51..11a36045 100644 --- a/autoload/ale/job.vim +++ b/autoload/ale/job.vim @@ -220,7 +220,7 @@ function! ale#job#SendRaw(job_id, string) abort if has('nvim') call jobsend(a:job_id, a:string) else - call ch_sendraw(job_getchannel(s:job_map[a:job_id]), a:string) + call ch_sendraw(job_getchannel(s:job_map[a:job_id].job), a:string) endif endfunction diff --git a/autoload/ale/lsp.vim b/autoload/ale/lsp.vim index acf47408..36620228 100644 --- a/autoload/ale/lsp.vim +++ b/autoload/ale/lsp.vim @@ -160,22 +160,28 @@ function! ale#lsp#SendMessageToProgram(executable, command, message, ...) abort let [l:id, l:data] = ale#lsp#CreateMessageData(a:message) let l:matches = filter(s:connections[:], 'v:val.executable ==# a:executable') - - if empty(l:matches) - " We haven't looked at this executable before. - " Create a new connection. - let l:conn = NewConnection() - endif + " Get the current connection or a new one. + let l:conn = !empty(l:matches) ? l:matches[0] : s:NewConnection() if !ale#job#IsRunning(l:conn.job_id) - let l:options = {'mode': 'raw', 'out_cb': 's:HandleCommandMessage'} + let l:options = { + \ 'mode': 'raw', + \ 'out_cb': function('s:HandleCommandMessage'), + \} let l:job_id = ale#job#Start(ale#job#PrepareCommand(a:command), l:options) endif - if l:job_id > 0 + if l:job_id <= 0 return 0 endif + " The ID is 0 when the message is a Notification, which is a JSON-RPC + " request for which the server must not return a response. + if l:id != 0 + " Add the callback, which the server will respond to later. + let l:conn.callback_map[l:id] = a:1 + endif + call ale#job#SendRaw(l:job_id, l:data) let l:conn.job_id = l:job_id @@ -201,18 +207,14 @@ function! ale#lsp#SendMessageToAddress(address, message, ...) abort let [l:id, l:data] = ale#lsp#CreateMessageData(a:message) let l:matches = filter(s:connections[:], 'v:val.address ==# a:address') - - if empty(l:matches) - " We haven't looked at this address before. - " Create a new connection. - let l:conn = NewConnection() - endif + " Get the current connection or a new one. + let l:conn = !empty(l:matches) ? l:matches[0] : s:NewConnection() if !has_key(l:conn, 'channel') || ch_status(l:conn.channel) !=# 'open' let l:conn.channnel = ch_open(a:address, { \ 'mode': 'raw', \ 'waittime': 0, - \ 'callback': 's:HandleChannelMessage', + \ 'callback': function('s:HandleChannelMessage'), \}) endif |