#830 Make the LSP socket code so far use the new socket API

This commit is contained in:
w0rp
2018-07-03 00:30:26 +01:00
parent 01c68fedd6
commit 5aba55bb86
3 changed files with 18 additions and 12 deletions

View File

@@ -241,9 +241,8 @@ function! ale#lsp#HandleMessage(conn, message) abort
endfor
endfunction
function! s:HandleChannelMessage(channel, message) abort
let l:info = ch_info(a:channel)
let l:address = l:info.hostname . l:info.address
function! s:HandleChannelMessage(channel_id, message) abort
let l:address = ale#socket#GetAddress(a:channel_id)
let l:conn = s:FindConnection('id', l:address)
call ale#lsp#HandleMessage(l:conn, a:message)
@@ -319,15 +318,13 @@ function! ale#lsp#ConnectToAddress(address, project_root, callback, initializati
" Get the current connection or a new one.
let l:conn = !empty(l:conn) ? l:conn : ale#lsp#NewConnection(a:initialization_options)
if !has_key(l:conn, 'channel') || ch_status(l:conn.channel) isnot# 'open'
let l:conn.channnel = ch_open(a:address, {
\ 'mode': 'raw',
\ 'waittime': 0,
if !has_key(l:conn, 'channel_id') || !ale#socket#IsOpen(l:conn.channel_id)
let l:conn.channnel_id = ale#socket#Open(a:address, {
\ 'callback': function('s:HandleChannelMessage'),
\})
endif
if ch_status(l:conn.channnel) is# 'fail'
if l:conn.channnel_id < 0
return 0
endif
@@ -343,8 +340,8 @@ endfunction
" queued messages.
function! ale#lsp#StopAll() abort
for l:conn in s:connections
if has_key(l:conn, 'channel')
call ch_close(l:conn.channel)
if has_key(l:conn, 'channel_id')
call ale#socket#Close(l:conn.channel_id)
else
call ale#job#Stop(l:conn.id)
endif
@@ -356,9 +353,9 @@ endfunction
function! s:SendMessageData(conn, data) abort
if has_key(a:conn, 'executable')
call ale#job#SendRaw(a:conn.id, a:data)
elseif has_key(a:conn, 'channel') && ch_status(a:conn.channnel) is# 'open'
elseif has_key(a:conn, 'channel_id') && ale#socket#IsOpen(a:conn.channel_id)
" Send the message to the server
call ch_sendraw(a:conn.channel, a:data)
call ale#socket#Send(a:conn.channel_id, a:data)
else
return 0
endif