Only send LSP config updates when the dict changes
Each LSP connection now stores its configuration dictionary. It is initially empty (`{}`) and is updated each time the LSP connection is started. When a change is detected, the workspace/didChangeConfiguration message is sent to the LSP servers with the updated configuration.
This commit is contained in:
parent
b5a7593577
commit
2ac9e2a29e
@ -19,6 +19,7 @@ function! ale#lsp#Register(executable_or_address, project, init_options) abort
|
||||
" initialized: 0 if the connection is ready, 1 otherwise.
|
||||
" init_request_id: The ID for the init request.
|
||||
" init_options: Options to send to the server.
|
||||
" config: Configuration settings to send to the server.
|
||||
" callback_list: A list of callbacks for handling LSP responses.
|
||||
" message_queue: Messages queued for sending to callbacks.
|
||||
" capabilities_queue: The list of callbacks to call with capabilities.
|
||||
@ -32,6 +33,7 @@ function! ale#lsp#Register(executable_or_address, project, init_options) abort
|
||||
\ 'initialized': 0,
|
||||
\ 'init_request_id': 0,
|
||||
\ 'init_options': a:init_options,
|
||||
\ 'config': {},
|
||||
\ 'callback_list': [],
|
||||
\ 'message_queue': [],
|
||||
\ 'capabilities_queue': [],
|
||||
@ -205,6 +207,25 @@ function! s:UpdateCapabilities(conn, capabilities) abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Update a connection's configuration dictionary and notify LSP servers
|
||||
" of any changes since the last update. Returns 1 if a configuration
|
||||
" update was sent; otherwise 0 will be returned.
|
||||
function! ale#lsp#UpdateConfig(conn_id, buffer, config) abort
|
||||
let l:conn = get(s:connections, a:conn_id, {})
|
||||
|
||||
if empty(l:conn) || a:config ==# l:conn.config " no-custom-checks
|
||||
return 0
|
||||
endif
|
||||
|
||||
let l:conn.config = a:config
|
||||
let l:message = ale#lsp#message#DidChangeConfiguration(a:buffer, a:config)
|
||||
|
||||
call ale#lsp#Send(a:conn_id, l:message)
|
||||
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
|
||||
function! ale#lsp#HandleInitResponse(conn, response) abort
|
||||
if get(a:response, 'method', '') is# 'initialize'
|
||||
let a:conn.initialized = 1
|
||||
|
@ -201,13 +201,6 @@ function! ale#lsp_linter#StartLSP(buffer, linter) abort
|
||||
endif
|
||||
|
||||
let l:config = ale#lsp_linter#GetConfig(a:buffer, a:linter)
|
||||
|
||||
if !empty(l:config)
|
||||
" set LSP configuration options (workspace/didChangeConfiguration)
|
||||
let l:config_message = ale#lsp#message#DidChangeConfiguration(a:buffer, l:config)
|
||||
call ale#lsp#Send(l:conn_id, l:config_message)
|
||||
endif
|
||||
|
||||
let l:language_id = ale#util#GetFunction(a:linter.language_callback)(a:buffer)
|
||||
|
||||
let l:details = {
|
||||
@ -218,6 +211,8 @@ function! ale#lsp_linter#StartLSP(buffer, linter) abort
|
||||
\ 'language_id': l:language_id,
|
||||
\}
|
||||
|
||||
call ale#lsp#UpdateConfig(l:conn_id, a:buffer, l:config)
|
||||
|
||||
if ale#lsp#OpenDocument(l:conn_id, a:buffer, l:language_id)
|
||||
if g:ale_history_enabled && !empty(l:command)
|
||||
call ale#history#Add(a:buffer, 'started', l:conn_id, l:command)
|
||||
|
@ -7,6 +7,7 @@ Before:
|
||||
\ 'initialized': 0,
|
||||
\ 'init_request_id': 0,
|
||||
\ 'init_options': {},
|
||||
\ 'config': {},
|
||||
\ 'callback_list': [],
|
||||
\ 'message_queue': [],
|
||||
\ 'capabilities_queue': [],
|
||||
|
17
test/lsp/test_update_config.vader
Normal file
17
test/lsp/test_update_config.vader
Normal file
@ -0,0 +1,17 @@
|
||||
Before:
|
||||
runtime autoload/ale/lsp.vim
|
||||
|
||||
let g:conn_id = ale#lsp#Register('executable', '/foo/bar', {})
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
unlet! g:conn_id
|
||||
|
||||
runtime autoload/ale/lsp.vim
|
||||
|
||||
Execute(Only send updates when the configuration dictionary changes):
|
||||
AssertEqual 0, ale#lsp#UpdateConfig(g:conn_id, bufnr(''), {})
|
||||
AssertEqual 1, ale#lsp#UpdateConfig(g:conn_id, bufnr(''), {'a': 1})
|
||||
AssertEqual 0, ale#lsp#UpdateConfig(g:conn_id, bufnr(''), {'a': 1})
|
||||
AssertEqual 1, ale#lsp#UpdateConfig(g:conn_id, bufnr(''), {})
|
Loading…
x
Reference in New Issue
Block a user