Close #3600 - Implement pull diagnostics in VimL

Implement pull diagnostics in the VimL implementation so ALE is able
to track when servers are busy checking files. Only servers that
support this feature will return diagnostics these ways.
This commit is contained in:
w0rp
2025-03-23 14:37:04 +00:00
parent 26ffb9dfa3
commit f90e72ae1f
9 changed files with 248 additions and 27 deletions

View File

@@ -410,6 +410,130 @@ Execute(LSP errors should mark linters no longer active):
AssertEqual [], g:ale_buffer_info[bufnr('')].active_linter_list
Execute(LSP pull model diagnostic responses should be handled):
let b:ale_linters = ['eclipselsp']
runtime ale_linters/java/eclipselsp.vim
if has('win32')
call ale#test#SetFilename('filename,[]^$.ts')
else
call ale#test#SetFilename('filename*?,{}[]^$.java')
endif
call ale#engine#InitBufferInfo(bufnr(''))
let g:ale_buffer_info[bufnr('')].active_linter_list = ale#linter#Get('eclipselsp')
call ale#lsp_linter#SetLSPLinterMap({'1': {'name': 'eclipselsp', 'aliases': [], 'lsp': 'stdio'}})
call ale#lsp_linter#SetDiagnosticURIMap({'347': ale#util#ToURI(expand('%:p'))})
if has('win32')
AssertEqual 'filename,[]^$.ts', expand('%:p:t')
else
AssertEqual 'filename*?,{}[]^$.java', expand('%:p:t')
endif
call ale#lsp_linter#HandleLSPResponse(1, {
\ 'jsonrpc':'2.0',
\ 'id': 347,
\ 'result': {
\ 'kind': 'full',
\ 'items': [
\ {
\ 'range': {
\ 'start': {
\ 'line': 0,
\ 'character':0
\ },
\ 'end': {
\ 'line': 0,
\ 'character':0
\ }
\ },
\ 'severity': 2,
\ 'code': "",
\ 'source': 'Java',
\ 'message': 'Missing JRE 1-8'
\ }
\ ]
\ },
\})
AssertEqual
\ [
\ {
\ 'lnum': 1,
\ 'bufnr': bufnr(''),
\ 'col': 1,
\ 'pattern': '',
\ 'valid': 1,
\ 'vcol': 0,
\ 'nr': -1,
\ 'type': 'W',
\ 'text': 'Missing JRE 1-8'
\ }
\ ],
\ ale#test#GetLoclistWithoutNewerKeys()
AssertEqual [], g:ale_buffer_info[bufnr('')].active_linter_list
Execute(LSP pull model diagnostic responses that are 'unchanged' should be handled):
let b:ale_linters = ['eclipselsp']
runtime ale_linters/java/eclipselsp.vim
if has('win32')
call ale#test#SetFilename('filename,[]^$.ts')
else
call ale#test#SetFilename('filename*?,{}[]^$.java')
endif
call ale#engine#InitBufferInfo(bufnr(''))
let g:ale_buffer_info[bufnr('')].active_linter_list = ale#linter#Get('eclipselsp')
let g:ale_buffer_info[bufnr('')].loclist = [
\ {
\ 'lnum': 1,
\ 'bufnr': bufnr(''),
\ 'col': 1,
\ 'pattern': '',
\ 'valid': 1,
\ 'vcol': 0,
\ 'nr': -1,
\ 'type': 'W',
\ 'text': 'Missing JRE 1-8'
\ },
\]
call ale#lsp_linter#SetLSPLinterMap({'1': {'name': 'eclipselsp', 'aliases': [], 'lsp': 'stdio'}})
call ale#lsp_linter#SetDiagnosticURIMap({'347': ale#util#ToURI(expand('%:p'))})
if has('win32')
AssertEqual 'filename,[]^$.ts', expand('%:p:t')
else
AssertEqual 'filename*?,{}[]^$.java', expand('%:p:t')
endif
call ale#lsp_linter#HandleLSPResponse(1, {
\ 'jsonrpc':'2.0',
\ 'id': 347,
\ 'result': {
\ 'kind': 'unchanged',
\ },
\})
AssertEqual
\ [
\ {
\ 'lnum': 1,
\ 'bufnr': bufnr(''),
\ 'col': 1,
\ 'pattern': '',
\ 'valid': 1,
\ 'vcol': 0,
\ 'nr': -1,
\ 'type': 'W',
\ 'text': 'Missing JRE 1-8'
\ }
\ ],
\ g:ale_buffer_info[bufnr('')].loclist
AssertEqual [], g:ale_buffer_info[bufnr('')].active_linter_list
Execute(LSP errors should be logged in the history):
call ale#lsp_linter#SetLSPLinterMap({'347': {'name': 'foobar', 'aliases': [], 'lsp': 'stdio'}})
call ale#lsp_linter#HandleLSPResponse(347, {

View File

@@ -248,6 +248,19 @@ Execute(ale#lsp#message#DidChangeConfiguration() should return correct messages)
\ ],
\ ale#lsp#message#DidChangeConfiguration(bufnr(''), g:ale_lsp_configuration)
Execute(ale#lsp#message#Diagnostic() should return correct messages):
AssertEqual
\ [
\ 0,
\ 'textDocument/diagnostic',
\ {
\ 'textDocument': {
\ 'uri': ale#path#ToFileURI(g:dir . '/foo/bar.ts'),
\ },
\ }
\ ],
\ ale#lsp#message#Diagnostic(bufnr(''))
Execute(ale#lsp#tsserver_message#Open() should return correct messages):
AssertEqual
\ [

View File

@@ -193,6 +193,10 @@ Before:
\ 'dynamicRegistration': v:false,
\ 'linkSupport': v:false,
\ },
\ 'diagnostic': {
\ 'dynamicRegistration': v:true,
\ 'relatedDocumentSupport': v:true,
\ },
\ 'publishDiagnostics': {
\ 'relatedInformation': v:true,
\ },

View File

@@ -90,6 +90,7 @@ Execute(Capabilities should be set up correctly):
\ 'includeText': 0,
\ 'references': 1,
\ 'rename': 1,
\ 'pull_model': 0,
\ 'symbol_search': 1,
\ 'typeDefinition': 0,
\ },
@@ -122,6 +123,7 @@ Execute(Disabled capabilities should be recognised correctly):
\ 'definitionProvider': v:false,
\ 'experimental': {},
\ 'documentHighlightProvider': v:true,
\ 'diagnosticProvider': {},
\ },
\ },
\})
@@ -140,6 +142,7 @@ Execute(Disabled capabilities should be recognised correctly):
\ 'includeText': 0,
\ 'references': 0,
\ 'rename': 0,
\ 'pull_model': 0,
\ 'symbol_search': 0,
\ 'typeDefinition': 0,
\ },
@@ -182,6 +185,9 @@ Execute(Capabilities should be enabled when sent as Dictionaries):
\ 'implementationProvider': {},
\ 'experimental': {},
\ 'documentHighlightProvider': v:true,
\ 'diagnosticProvider': {
\ 'interFileDependencies': v:false,
\ },
\ 'workspaceSymbolProvider': {}
\ },
\ },
@@ -201,6 +207,7 @@ Execute(Capabilities should be enabled when sent as Dictionaries):
\ 'includeText': 1,
\ 'references': 1,
\ 'rename': 1,
\ 'pull_model': 1,
\ 'symbol_search': 1,
\ 'typeDefinition': 1,
\ },

View File

@@ -21,14 +21,14 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle errors):
\ 'code': 'some-error',
\ }
\ ],
\ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
\ ale#lsp#response#ReadDiagnostics([
\ {
\ 'severity': 1,
\ 'range': Range(2, 10, 4, 15),
\ 'code': 'some-error',
\ 'message': 'Something went wrong!',
\ },
\ ]}})
\ ])
Execute(ale#lsp#response#ReadDiagnostics() should handle warnings):
AssertEqual [
@@ -42,14 +42,14 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle warnings):
\ 'code': 'some-warning',
\ }
\ ],
\ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
\ ale#lsp#response#ReadDiagnostics([
\ {
\ 'severity': 2,
\ 'range': Range(1, 3, 1, 3),
\ 'code': 'some-warning',
\ 'message': 'Something went wrong!',
\ },
\ ]}})
\ ])
Execute(ale#lsp#response#ReadDiagnostics() should treat messages with missing severity as errors):
AssertEqual [
@@ -63,13 +63,13 @@ Execute(ale#lsp#response#ReadDiagnostics() should treat messages with missing se
\ 'code': 'some-error',
\ }
\ ],
\ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
\ ale#lsp#response#ReadDiagnostics([
\ {
\ 'range': Range(2, 10, 4, 15),
\ 'code': 'some-error',
\ 'message': 'Something went wrong!',
\ },
\ ]}})
\ ])
Execute(ale#lsp#response#ReadDiagnostics() should handle messages without codes):
AssertEqual [
@@ -82,12 +82,12 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle messages without codes)
\ 'end_col': 15,
\ }
\ ],
\ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
\ ale#lsp#response#ReadDiagnostics([
\ {
\ 'range': Range(2, 10, 4, 15),
\ 'message': 'Something went wrong!',
\ },
\ ]}})
\ ])
Execute(ale#lsp#response#ReadDiagnostics() should include sources in detail):
AssertEqual [
@@ -101,13 +101,13 @@ Execute(ale#lsp#response#ReadDiagnostics() should include sources in detail):
\ 'end_col': 22,
\ }
\ ],
\ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
\ ale#lsp#response#ReadDiagnostics([
\ {
\ 'range': Range(9, 14, 11, 22),
\ 'message': 'Something went wrong!',
\ 'source': 'tslint',
\ }
\ ]}})
\ ])
Execute(ale#lsp#response#ReadDiagnostics() should keep detail with line breaks but replace with spaces in text):
AssertEqual [
@@ -121,13 +121,13 @@ Execute(ale#lsp#response#ReadDiagnostics() should keep detail with line breaks b
\ 'end_col': 22,
\ }
\ ],
\ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
\ ale#lsp#response#ReadDiagnostics([
\ {
\ 'range': Range(9, 14, 11, 22),
\ 'message': "cannot borrow `cap` as mutable\r\nmore than once at a time\n\nmutable borrow starts here\rin previous iteration of loop",
\ 'source': 'rustc',
\ }
\ ]}})
\ ])
Execute(ale#lsp#response#ReadDiagnostics() should consider -1 to be a meaningless code):
AssertEqual [
@@ -140,13 +140,13 @@ Execute(ale#lsp#response#ReadDiagnostics() should consider -1 to be a meaningles
\ 'end_col': 15,
\ }
\ ],
\ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
\ ale#lsp#response#ReadDiagnostics([
\ {
\ 'range': Range(2, 10, 4, 15),
\ 'message': 'Something went wrong!',
\ 'code': -1,
\ },
\ ]}})
\ ])
Execute(ale#lsp#response#ReadDiagnostics() should handle multiple messages):
AssertEqual [
@@ -167,7 +167,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle multiple messages):
\ 'end_col': 4,
\ },
\ ],
\ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
\ ale#lsp#response#ReadDiagnostics([
\ {
\ 'range': Range(0, 2, 0, 2),
\ 'message': 'Something went wrong!',
@@ -177,7 +177,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should handle multiple messages):
\ 'range': Range(1, 4, 1, 4),
\ 'message': 'A warning',
\ },
\ ]}})
\ ])
Execute(ale#lsp#response#ReadDiagnostics() should use relatedInformation for detail):
AssertEqual [
@@ -191,7 +191,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should use relatedInformation for det
\ 'detail': "Something went wrong!\n/tmp/someotherfile.txt:43:80:\n\tmight be this"
\ }
\ ],
\ ale#lsp#response#ReadDiagnostics({'params': {'uri': 'filename.ts', 'diagnostics': [
\ ale#lsp#response#ReadDiagnostics([
\ {
\ 'range': Range(0, 2, 0, 2),
\ 'message': 'Something went wrong!',
@@ -206,7 +206,7 @@ Execute(ale#lsp#response#ReadDiagnostics() should use relatedInformation for det
\ }
\ }]
\ }
\ ]}})
\ ])
Execute(ale#lsp#response#ReadTSServerDiagnostics() should handle tsserver responses):
AssertEqual