diff options
author | w0rp <devw0rp@gmail.com> | 2017-05-16 19:37:58 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-05-16 19:38:05 +0100 |
commit | 1b53fa841b914478bd2c68c4c471d9be4ad05798 (patch) | |
tree | 9824d204f28d8da9666c1b8f7342c0b8b7915a97 | |
parent | a65358cfce6f2748918ef822c69a8f56eec83f20 (diff) | |
download | ale-1b53fa841b914478bd2c68c4c471d9be4ad05798.zip |
Fix some problems with LSP functions
-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 |