Introduce an ALELSPStarted autocommand (#3878)

This User autocommand is trigged immediately after an LSP process is
successfully initialized. This provides a way to perform any additional
initialization work, such as setting up buffer-level mappings.
This commit is contained in:
Jon Parise
2021-09-04 18:07:53 -07:00
committed by GitHub
parent b9fdb91e92
commit 8fd23f4b71
3 changed files with 102 additions and 22 deletions

View File

@@ -271,6 +271,30 @@ function! ale#lsp_linter#OnInit(linter, details, Callback) abort
call ale#lsp#NotifyForChanges(l:conn_id, l:buffer)
endif
" Tell the relevant buffer that the LSP has started via an autocmd.
if l:buffer > 0
if l:buffer == bufnr('')
silent doautocmd <nomodeline> User ALELSPStarted
else
execute 'augroup ALELSPStartedGroup' . l:buffer
autocmd!
execute printf(
\ 'autocmd BufEnter <buffer=%d>'
\ . ' doautocmd <nomodeline> User ALELSPStarted',
\ l:buffer
\)
" Replicate ++once behavior for backwards compatibility.
execute printf(
\ 'autocmd BufEnter <buffer=%d>'
\ . ' autocmd! ALELSPStartedGroup%d',
\ l:buffer, l:buffer
\)
augroup END
endif
endif
call a:Callback(a:linter, a:details)
endfunction