Close #830 - Implement LSP connections via TCP sockets
This commit is contained in:
parent
5aba55bb86
commit
e46474ac0a
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
" A List of connections, used for tracking servers which have been connected
|
" A List of connections, used for tracking servers which have been connected
|
||||||
" to, and programs which are run.
|
" to, and programs which are run.
|
||||||
let s:connections = []
|
let s:connections = get(s:, 'connections', [])
|
||||||
let g:ale_lsp_next_message_id = 1
|
let g:ale_lsp_next_message_id = 1
|
||||||
|
|
||||||
" Exposed only so tests can get at it.
|
" Exposed only so tests can get at it.
|
||||||
@ -36,7 +36,7 @@ endfunction
|
|||||||
|
|
||||||
function! s:FindConnection(key, value) abort
|
function! s:FindConnection(key, value) abort
|
||||||
for l:conn in s:connections
|
for l:conn in s:connections
|
||||||
if has_key(l:conn, a:key) && get(l:conn, a:key) == a:value
|
if has_key(l:conn, a:key) && get(l:conn, a:key) is# a:value
|
||||||
return l:conn
|
return l:conn
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
@ -319,13 +319,13 @@ function! ale#lsp#ConnectToAddress(address, project_root, callback, initializati
|
|||||||
let l:conn = !empty(l:conn) ? l:conn : ale#lsp#NewConnection(a:initialization_options)
|
let l:conn = !empty(l:conn) ? l:conn : ale#lsp#NewConnection(a:initialization_options)
|
||||||
|
|
||||||
if !has_key(l:conn, 'channel_id') || !ale#socket#IsOpen(l:conn.channel_id)
|
if !has_key(l:conn, 'channel_id') || !ale#socket#IsOpen(l:conn.channel_id)
|
||||||
let l:conn.channnel_id = ale#socket#Open(a:address, {
|
let l:conn.channel_id = ale#socket#Open(a:address, {
|
||||||
\ 'callback': function('s:HandleChannelMessage'),
|
\ 'callback': function('s:HandleChannelMessage'),
|
||||||
\})
|
\})
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if l:conn.channnel_id < 0
|
if l:conn.channel_id < 0
|
||||||
return 0
|
return ''
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let l:conn.id = a:address
|
let l:conn.id = a:address
|
||||||
@ -333,7 +333,7 @@ function! ale#lsp#ConnectToAddress(address, project_root, callback, initializati
|
|||||||
call uniq(sort(add(l:conn.callback_list, a:callback)))
|
call uniq(sort(add(l:conn.callback_list, a:callback)))
|
||||||
call ale#lsp#RegisterProject(l:conn, a:project_root)
|
call ale#lsp#RegisterProject(l:conn, a:project_root)
|
||||||
|
|
||||||
return 1
|
return a:address
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Stop all LSP connections, closing all jobs and channels, and removing any
|
" Stop all LSP connections, closing all jobs and channels, and removing any
|
||||||
|
@ -166,7 +166,7 @@ function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort
|
|||||||
|
|
||||||
let l:language_id = ale#util#GetFunction(a:linter.language_callback)(a:buffer)
|
let l:language_id = ale#util#GetFunction(a:linter.language_callback)(a:buffer)
|
||||||
|
|
||||||
if !l:conn_id
|
if empty(l:conn_id)
|
||||||
if g:ale_history_enabled && !empty(l:command)
|
if g:ale_history_enabled && !empty(l:command)
|
||||||
call ale#history#Add(a:buffer, 'failed', l:conn_id, l:command)
|
call ale#history#Add(a:buffer, 'failed', l:conn_id, l:command)
|
||||||
endif
|
endif
|
||||||
|
17
doc/ale.txt
17
doc/ale.txt
@ -2371,8 +2371,16 @@ ale#linter#Define(filetype, linter) *ale#linter#Define()*
|
|||||||
|
|
||||||
When this argument is set to `'stdio'`, then the
|
When this argument is set to `'stdio'`, then the
|
||||||
linter will be defined as an LSP linter which keeps a
|
linter will be defined as an LSP linter which keeps a
|
||||||
process for a language server runnning, and
|
process for a language server running, and
|
||||||
communicates with it directly via a |channel|.
|
communicates with it directly via a |channel|.
|
||||||
|
`executable` or `executable_callback` must be set,
|
||||||
|
and `command` or `command_callback` must be set.
|
||||||
|
|
||||||
|
When this argument is set to `'socket'`, then the
|
||||||
|
linter will be defined as an LSP linter via a TCP
|
||||||
|
socket connection. `address_callback` must be set
|
||||||
|
with a callback returning an address to connect to.
|
||||||
|
ALE will not start a server automatically.
|
||||||
|
|
||||||
When this argument is not empty, only one of either
|
When this argument is not empty, only one of either
|
||||||
`language` or `language_callback` must be defined,
|
`language` or `language_callback` must be defined,
|
||||||
@ -2388,6 +2396,13 @@ ale#linter#Define(filetype, linter) *ale#linter#Define()*
|
|||||||
`initialization_options_callback` may be defined to
|
`initialization_options_callback` may be defined to
|
||||||
pass initialization options to the LSP.
|
pass initialization options to the LSP.
|
||||||
|
|
||||||
|
`address_callback` A |String| or |Funcref| for a callback function
|
||||||
|
accepting a buffer number. A |String| should be
|
||||||
|
returned with an address to connect to.
|
||||||
|
|
||||||
|
This argument must only be set if the `lsp` argument
|
||||||
|
is set to `'socket'`.
|
||||||
|
|
||||||
`project_root_callback` A |String| or |Funcref| for a callback function
|
`project_root_callback` A |String| or |Funcref| for a callback function
|
||||||
accepting a buffer number. A |String| should be
|
accepting a buffer number. A |String| should be
|
||||||
returned representing the path to the project for the
|
returned representing the path to the project for the
|
||||||
|
Loading…
Reference in New Issue
Block a user