Supply language_id values to Neovim LSP API

Change logic so ALE's LSP implementation and the Neovim LSP client
retrieve the language_id for language clients at roughly the same time
via the same means. This makes ALE inform the language server what the
language for the language is for clients.
This commit is contained in:
w0rp
2025-03-18 14:05:58 +00:00
parent 4f4d68f153
commit 73b568b071
19 changed files with 65 additions and 41 deletions

View File

@@ -37,24 +37,24 @@ After:
runtime autoload/ale/lsp.vim
Execute(No errors should be thrown if the connection is not initialized):
call ale#lsp#Register('command', '/foo', {})
call ale#lsp#Register('command', '/foo', '', {})
call MarkDocumentOpened()
call ale#engine#Cleanup(bufnr(''))
AssertEqual [], g:message_list
Execute(No messages should be sent if the document wasn't opened):
call ale#lsp#Register('command', '/foo', {})
call ale#lsp#Register('command', '/foo', '', {})
call MarkAllConnectionsInitialized()
call ale#engine#Cleanup(bufnr(''))
AssertEqual [], g:message_list
Execute(A message should be sent if the document was opened):
call ale#lsp#Register('command', '/foo', {})
call ale#lsp#Register('command', '/foo', 'lang', {})
call MarkAllConnectionsInitialized()
call ale#lsp#OpenDocument('command:/foo', bufnr(''), 'lang')
call ale#lsp#OpenDocument('command:/foo', bufnr(''))
call ale#engine#Cleanup(bufnr(''))
" We should only send the message once.
call ale#engine#Cleanup(bufnr(''))
@@ -78,10 +78,10 @@ Execute(A message should be sent if the document was opened):
\ g:message_list
Execute(A message should be sent if the document was opened for tsserver):
call ale#lsp#Register('command', '/foo', {})
call ale#lsp#Register('command', '/foo', 'lang', {})
call ale#lsp#MarkConnectionAsTsserver('command:/foo')
call ale#lsp#OpenDocument('command:/foo', bufnr(''), 'lang')
call ale#lsp#OpenDocument('command:/foo', bufnr(''))
call ale#engine#Cleanup(bufnr(''))
" We should only send the message once.
call ale#engine#Cleanup(bufnr(''))
@@ -94,12 +94,12 @@ Execute(A message should be sent if the document was opened for tsserver):
\ g:message_list
Execute(Re-opening and closing the documents should work):
call ale#lsp#Register('command', '/foo', {})
call ale#lsp#Register('command', '/foo', 'lang', {})
call MarkAllConnectionsInitialized()
call ale#lsp#OpenDocument('command:/foo', bufnr(''), 'lang')
call ale#lsp#OpenDocument('command:/foo', bufnr(''))
call ale#engine#Cleanup(bufnr(''))
call ale#lsp#OpenDocument('command:/foo', bufnr(''), 'lang')
call ale#lsp#OpenDocument('command:/foo', bufnr(''))
call ale#engine#Cleanup(bufnr(''))
AssertEqual
@@ -134,12 +134,12 @@ Execute(Re-opening and closing the documents should work):
\ g:message_list
Execute(Messages for closing documents should be sent to each server):
call ale#lsp#Register('command', '/foo', {})
call ale#lsp#Register('command', '/bar', {})
call ale#lsp#Register('command', '/foo', 'lang', {})
call ale#lsp#Register('command', '/bar', 'lang', {})
call MarkAllConnectionsInitialized()
call ale#lsp#OpenDocument('command:/foo', bufnr(''), 'lang')
call ale#lsp#OpenDocument('command:/bar', bufnr(''), 'lang')
call ale#lsp#OpenDocument('command:/foo', bufnr(''))
call ale#lsp#OpenDocument('command:/bar', bufnr(''))
call ale#engine#Cleanup(bufnr(''))
" We should only send the message once.
call ale#engine#Cleanup(bufnr(''))

View File

@@ -39,7 +39,7 @@ Before:
let g:ale_linters = {'foobar': ['dummy_linter']}
function! ale#lsp_linter#StartLSP(buffer, linter, Callback) abort
let g:conn_id = ale#lsp#Register('executable', '/foo/bar', {})
let g:conn_id = ale#lsp#Register('executable', '/foo/bar', 'foobar', {})
call ale#lsp#MarkDocumentAsOpen(g:conn_id, a:buffer)
let l:details = {
\ 'command': 'foobar',

View File

@@ -39,7 +39,7 @@ Before:
" Replace the StartLSP function to mock an LSP linter
function! ale#lsp_linter#StartLSP(buffer, linter, Callback) abort
let g:conn_id = ale#lsp#Register(g:executable_or_address, g:project_root, {})
let g:conn_id = ale#lsp#Register(g:executable_or_address, g:project_root, '', {})
call ale#lsp#MarkDocumentAsOpen(g:conn_id, a:buffer)
call ale#lsp#HandleMessage(g:conn_id, Encode({'method': 'initialize'}))

View File

@@ -441,7 +441,7 @@ Execute(Deferred addresses should be handled correctly):
call AssertInitSuccess('foo', 'localhost:1234', 'foobar', '/foo/bar', '', bufnr(''))
Execute(Servers that have crashed should be restarted):
call ale#lsp#Register('foo', '/foo/bar', {})
call ale#lsp#Register('foo', '/foo/bar', '', {})
call extend(ale#lsp#GetConnections()['foo:/foo/bar'], {'initialized': 1})
" Starting the program again should reset initialized to `0`.

View File

@@ -4,7 +4,7 @@ Before:
let g:message_list = []
" Register a fake connection and get it for tests.
call ale#lsp#Register('ale-fake-lsp-server', '/code', {})
call ale#lsp#Register('ale-fake-lsp-server', '/code', '', {})
let b:conn = ale#lsp#GetConnections()['ale-fake-lsp-server:/code']
function! ale#lsp#Send(conn_id, message) abort

View File

@@ -1,7 +1,7 @@
Before:
runtime autoload/ale/lsp.vim
let g:conn_id = ale#lsp#Register('executable', '/foo/bar', {})
let g:conn_id = ale#lsp#Register('executable', '/foo/bar', '', {})
" Stub out this function, so we test updating configs.
function! ale#lsp#Send(conn_id, message) abort