Fix tests for Neovim LSP integration

This commit is contained in:
w0rp
2025-03-18 11:38:06 +00:00
parent 25547c856e
commit 4f4d68f153
3 changed files with 64 additions and 60 deletions

View File

@@ -320,8 +320,9 @@ function! ale#lsp#UpdateConfig(conn_id, buffer, config) abort
endfunction endfunction
function! ale#lsp#CallInitCallbacks(conn_id) abort function! ale#lsp#CallInitCallbacks(conn_id) abort
let l:conn = s:connections[a:conn_id] let l:conn = get(s:connections, a:conn_id, {})
if !empty(l:conn)
" Ensure the connection is marked as initialized. " Ensure the connection is marked as initialized.
" For integration with Neovim's LSP tooling this ensures immediately " For integration with Neovim's LSP tooling this ensures immediately
" call OnInit functions in Vim after the `on_init` callback is called. " call OnInit functions in Vim after the `on_init` callback is called.
@@ -333,6 +334,7 @@ function! ale#lsp#CallInitCallbacks(conn_id) abort
endfor endfor
let l:conn.init_queue = [] let l:conn.init_queue = []
endif
endfunction endfunction
function! ale#lsp#HandleInitResponse(conn, response) abort function! ale#lsp#HandleInitResponse(conn, response) abort

View File

@@ -2,30 +2,10 @@ Before:
runtime autoload/ale/lsp.vim runtime autoload/ale/lsp.vim
let g:message_list = [] let g:message_list = []
let b:conn = {
\ 'id': 1, " Register a fake connection and get it for tests.
\ 'is_tsserver': 0, call ale#lsp#Register('ale-fake-lsp-server', '/code', {})
\ 'data': '', let b:conn = ale#lsp#GetConnections()['ale-fake-lsp-server:/code']
\ 'root': '/foo/bar',
\ 'open_documents': {},
\ 'initialized': 0,
\ 'init_request_id': 0,
\ 'init_options': {},
\ 'config': {},
\ 'callback_list': [],
\ 'message_queue': [],
\ 'init_queue': [],
\ 'capabilities': {
\ 'hover': 0,
\ 'rename': 0,
\ 'references': 0,
\ 'completion': 0,
\ 'completion_trigger_characters': [],
\ 'definition': 0,
\ 'symbol_search': 0,
\ 'code_actions': 0,
\ },
\}
function! ale#lsp#Send(conn_id, message) abort function! ale#lsp#Send(conn_id, message) abort
call add(g:message_list, a:message) call add(g:message_list, a:message)
@@ -34,6 +14,9 @@ Before:
endfunction endfunction
After: After:
" Remove the connection with the ID.
call ale#lsp#RemoveConnectionWithID(b:conn.id)
unlet! b:conn unlet! b:conn
unlet! g:message_list unlet! g:message_list
@@ -58,7 +41,7 @@ Execute(Other messages should not initialize projects):
AssertEqual 0, b:conn.initialized AssertEqual 0, b:conn.initialized
AssertEqual [], g:message_list AssertEqual [], g:message_list
Execute(Capabilities should bet set up correctly): Execute(Capabilities should be set up correctly):
call ale#lsp#HandleInitResponse(b:conn, { call ale#lsp#HandleInitResponse(b:conn, {
\ 'jsonrpc': '2.0', \ 'jsonrpc': '2.0',
\ 'id': 1, \ 'id': 1,
@@ -96,14 +79,19 @@ Execute(Capabilities should bet set up correctly):
AssertEqual 1, b:conn.initialized AssertEqual 1, b:conn.initialized
AssertEqual AssertEqual
\ { \ {
\ 'completion_trigger_characters': ['.'],
\ 'completion': 1,
\ 'references': 1,
\ 'hover': 1,
\ 'definition': 1,
\ 'symbol_search': 1,
\ 'rename': 1,
\ 'code_actions': 1, \ 'code_actions': 1,
\ 'completion': 1,
\ 'completion_trigger_characters': ['.'],
\ 'definition': 1,
\ 'did_save': 0,
\ 'filerename': 0,
\ 'hover': 1,
\ 'implementation': 0,
\ 'includeText': 0,
\ 'references': 1,
\ 'rename': 1,
\ 'symbol_search': 1,
\ 'typeDefinition': 0,
\ }, \ },
\ b:conn.capabilities \ b:conn.capabilities
AssertEqual [[1, 'initialized', {}]], g:message_list AssertEqual [[1, 'initialized', {}]], g:message_list
@@ -141,19 +129,24 @@ Execute(Disabled capabilities should be recognised correctly):
AssertEqual 1, b:conn.initialized AssertEqual 1, b:conn.initialized
AssertEqual AssertEqual
\ { \ {
\ 'completion_trigger_characters': [],
\ 'completion': 0,
\ 'references': 0,
\ 'hover': 0,
\ 'definition': 0,
\ 'symbol_search': 0,
\ 'rename': 0,
\ 'code_actions': 0, \ 'code_actions': 0,
\ 'completion': 0,
\ 'completion_trigger_characters': [],
\ 'definition': 0,
\ 'did_save': 0,
\ 'filerename': 0,
\ 'hover': 0,
\ 'implementation': 0,
\ 'includeText': 0,
\ 'references': 0,
\ 'rename': 0,
\ 'symbol_search': 0,
\ 'typeDefinition': 0,
\ }, \ },
\ b:conn.capabilities \ b:conn.capabilities
AssertEqual [[1, 'initialized', {}]], g:message_list AssertEqual [[1, 'initialized', {}]], g:message_list
Execute(Capabilities should be enabled when send as Dictionaries): Execute(Capabilities should be enabled when sent as Dictionaries):
call ale#lsp#HandleInitResponse(b:conn, { call ale#lsp#HandleInitResponse(b:conn, {
\ 'jsonrpc': '2.0', \ 'jsonrpc': '2.0',
\ 'id': 1, \ 'id': 1,
@@ -174,7 +167,11 @@ Execute(Capabilities should be enabled when send as Dictionaries):
\ 'resolveProvider': v:false \ 'resolveProvider': v:false
\ }, \ },
\ 'referencesProvider': {}, \ 'referencesProvider': {},
\ 'textDocumentSync': 2, \ 'textDocumentSync': {
\ 'save': {
\ 'includeText': v:true
\ }
\ },
\ 'documentFormattingProvider': v:true, \ 'documentFormattingProvider': v:true,
\ 'codeActionProvider': v:true, \ 'codeActionProvider': v:true,
\ 'signatureHelpProvider': { \ 'signatureHelpProvider': {
@@ -193,16 +190,19 @@ Execute(Capabilities should be enabled when send as Dictionaries):
AssertEqual 1, b:conn.initialized AssertEqual 1, b:conn.initialized
AssertEqual AssertEqual
\ { \ {
\ 'completion_trigger_characters': ['.'],
\ 'completion': 1,
\ 'references': 1,
\ 'hover': 1,
\ 'definition': 1,
\ 'typeDefinition': 1,
\ 'implementation': 1,
\ 'symbol_search': 1,
\ 'rename': 1,
\ 'code_actions': 1, \ 'code_actions': 1,
\ 'completion': 1,
\ 'completion_trigger_characters': ['.'],
\ 'definition': 1,
\ 'did_save': 1,
\ 'filerename': 0,
\ 'hover': 1,
\ 'implementation': 1,
\ 'includeText': 1,
\ 'references': 1,
\ 'rename': 1,
\ 'symbol_search': 1,
\ 'typeDefinition': 1,
\ }, \ },
\ b:conn.capabilities \ b:conn.capabilities
AssertEqual [[1, 'initialized', {}]], g:message_list AssertEqual [[1, 'initialized', {}]], g:message_list

View File

@@ -4,6 +4,8 @@
let g:ale_set_lists_synchronously = 1 let g:ale_set_lists_synchronously = 1
" Disable Neovim diagnostics by default for CI tests. " Disable Neovim diagnostics by default for CI tests.
let g:ale_use_neovim_diagnostics_api = 0 let g:ale_use_neovim_diagnostics_api = 0
" Disable Neovim native LSP API by default for CI tests.
let g:ale_use_neovim_lsp_api = 0
" This lowercase highlight definition is needed for highlight tests. " This lowercase highlight definition is needed for highlight tests.
hi link aleerrorline spellbad hi link aleerrorline spellbad