Merge pull request #2524 from hsanson/2521-fix-lsp-diagnostics-buffer-match
WIP Fix HandleLSPDiagnostics buffer match logic.
This commit is contained in:
commit
bb08b81bf7
5 changed files with 181 additions and 7 deletions
|
@ -31,7 +31,7 @@ endfunction
|
|||
function! s:HandleLSPDiagnostics(conn_id, response) abort
|
||||
let l:linter_name = s:lsp_linter_map[a:conn_id]
|
||||
let l:filename = ale#path#FromURI(a:response.params.uri)
|
||||
let l:buffer = bufnr(l:filename)
|
||||
let l:buffer = bufnr('^' . l:filename . '$')
|
||||
let l:info = get(g:ale_buffer_info, l:buffer, {})
|
||||
|
||||
if empty(l:info)
|
||||
|
@ -49,7 +49,7 @@ endfunction
|
|||
|
||||
function! s:HandleTSServerDiagnostics(response, error_type) abort
|
||||
let l:linter_name = 'tsserver'
|
||||
let l:buffer = bufnr(a:response.body.file)
|
||||
let l:buffer = bufnr('^' . a:response.body.file . '$')
|
||||
let l:info = get(g:ale_buffer_info, l:buffer, {})
|
||||
|
||||
if empty(l:info)
|
||||
|
|
|
@ -9,6 +9,7 @@ Before:
|
|||
call ale#test#SetFilename('dummy.txt')
|
||||
|
||||
runtime autoload/ale/lsp.vim
|
||||
runtime autoload/ale/lsp_linter.vim
|
||||
|
||||
let g:ale_disable_lsp = 0
|
||||
unlet! b:ale_disable_lsp
|
||||
|
|
|
@ -1,19 +1,42 @@
|
|||
Before:
|
||||
Save g:ale_set_lists_synchronously
|
||||
Save g:ale_buffer_info
|
||||
Save g:ale_lsp_error_messages
|
||||
Save g:ale_set_loclist
|
||||
Save g:ale_set_signs
|
||||
Save g:ale_set_quickfix
|
||||
Save g:ale_set_highlights
|
||||
Save g:ale_echo_cursor
|
||||
Save g:ale_disable_lsp
|
||||
Save g:ale_history_enabled
|
||||
Save g:ale_history_log_output
|
||||
|
||||
let g:ale_disable_lsp = 0
|
||||
let g:ale_set_lists_synchronously = 1
|
||||
let g:ale_buffer_info = {}
|
||||
let g:ale_set_loclist = 1
|
||||
" Disable features we don't need for these tests.
|
||||
let g:ale_set_signs = 0
|
||||
let g:ale_set_quickfix = 0
|
||||
let g:ale_set_highlights = 0
|
||||
let g:ale_echo_cursor = 0
|
||||
let g:ale_history_enabled = 1
|
||||
let g:ale_history_log_output = 1
|
||||
|
||||
unlet! g:ale_lsp_error_messages
|
||||
unlet! b:ale_linters
|
||||
unlet! b:ale_disable_lsp
|
||||
|
||||
call ale#linter#Reset()
|
||||
call ale#test#SetDirectory('/testplugin/test')
|
||||
call setloclist(0, [])
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
unlet! b:ale_linters
|
||||
|
||||
call setloclist(0, [])
|
||||
call ale#test#RestoreDirectory()
|
||||
call ale#linter#Reset()
|
||||
call ale#lsp_linter#ClearLSPData()
|
||||
|
@ -92,6 +115,35 @@ Execute(tsserver syntax error responses should be handled correctly):
|
|||
\ ],
|
||||
\ ale#test#GetLoclistWithoutModule()
|
||||
|
||||
" Syntax errors on the project root should not populate the LocList.
|
||||
call ale#lsp_linter#HandleLSPResponse(1, {
|
||||
\ 'seq': 0,
|
||||
\ 'type': 'event',
|
||||
\ 'event': 'syntaxDiag',
|
||||
\ 'body': {
|
||||
\ 'file': g:dir,
|
||||
\ 'diagnostics':[
|
||||
\ {
|
||||
\ 'start': {
|
||||
\ 'line':2,
|
||||
\ 'offset':14,
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line':2,
|
||||
\ 'offset':15,
|
||||
\ },
|
||||
\ 'text': ''','' expected.',
|
||||
\ "code":1005
|
||||
\ },
|
||||
\ ],
|
||||
\ },
|
||||
\})
|
||||
|
||||
AssertEqual
|
||||
\ [
|
||||
\ ],
|
||||
\ ale#test#GetLoclistWithoutModule()
|
||||
|
||||
Execute(tsserver semantic error responses should be handled correctly):
|
||||
runtime ale_linters/typescript/tsserver.vim
|
||||
call ale#test#SetFilename('filename.ts')
|
||||
|
@ -165,6 +217,35 @@ Execute(tsserver semantic error responses should be handled correctly):
|
|||
\ ],
|
||||
\ ale#test#GetLoclistWithoutModule()
|
||||
|
||||
" Semantic errors on the project root should not populate the LocList.
|
||||
call ale#lsp_linter#HandleLSPResponse(1, {
|
||||
\ 'seq': 0,
|
||||
\ 'type': 'event',
|
||||
\ 'event': 'semanticDiag',
|
||||
\ 'body': {
|
||||
\ 'file': g:dir,
|
||||
\ 'diagnostics':[
|
||||
\ {
|
||||
\ 'start': {
|
||||
\ 'line':2,
|
||||
\ 'offset':14,
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line':2,
|
||||
\ 'offset':15,
|
||||
\ },
|
||||
\ 'text': 'Some semantic error',
|
||||
\ "code":1005
|
||||
\ },
|
||||
\ ],
|
||||
\ },
|
||||
\})
|
||||
|
||||
AssertEqual
|
||||
\ [
|
||||
\ ],
|
||||
\ ale#test#GetLoclistWithoutModule()
|
||||
|
||||
Execute(tsserver errors should mark tsserver no longer active):
|
||||
let b:ale_linters = ['tsserver']
|
||||
runtime ale_linters/typescript/tsserver.vim
|
||||
|
@ -186,6 +267,93 @@ Execute(tsserver errors should mark tsserver no longer active):
|
|||
|
||||
AssertEqual [], g:ale_buffer_info[bufnr('')].active_linter_list
|
||||
|
||||
Execute(LSP diagnostics responses should be handled correctly):
|
||||
let b:ale_linters = ['eclipselsp']
|
||||
runtime ale_linters/java/eclipselsp.vim
|
||||
call ale#test#SetFilename('filename.java')
|
||||
call ale#engine#InitBufferInfo(bufnr(''))
|
||||
call ale#lsp_linter#SetLSPLinterMap({'1': 'eclipselsp'})
|
||||
|
||||
call ale#lsp_linter#HandleLSPResponse(1, {
|
||||
\ 'jsonrpc':'2.0',
|
||||
\ 'method':'textDocument/publishDiagnostics',
|
||||
\ 'params': {
|
||||
\ 'uri':'file://' . g:dir . '/filename.java',
|
||||
\ 'diagnostics': [
|
||||
\ {
|
||||
\ '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#GetLoclistWithoutModule()
|
||||
|
||||
Execute(LSP diagnostics responses on project root should not populate loclist):
|
||||
let b:ale_linters = ['eclipselsp']
|
||||
runtime ale_linters/java/eclipselsp.vim
|
||||
call ale#test#SetFilename('filename.java')
|
||||
call ale#engine#InitBufferInfo(bufnr(''))
|
||||
call ale#lsp_linter#SetLSPLinterMap({'1': 'eclipselsp'})
|
||||
|
||||
call ale#lsp_linter#HandleLSPResponse(1, {
|
||||
\ 'jsonrpc':'2.0',
|
||||
\ 'method':'textDocument/publishDiagnostics',
|
||||
\ 'params': {
|
||||
\ 'uri':'file://' . g:dir,
|
||||
\ 'diagnostics': [
|
||||
\ {
|
||||
\ 'range': {
|
||||
\ 'start': {
|
||||
\ 'line': 0,
|
||||
\ 'character':0
|
||||
\ },
|
||||
\ 'end': {
|
||||
\ 'line': 0,
|
||||
\ 'character':0
|
||||
\ }
|
||||
\ },
|
||||
\ 'severity': 2,
|
||||
\ 'code': "",
|
||||
\ 'source': 'Java',
|
||||
\ 'message': 'Missing JRE 1-8'
|
||||
\ }
|
||||
\ ]
|
||||
\ }
|
||||
\})
|
||||
|
||||
AssertEqual
|
||||
\ [
|
||||
\ ],
|
||||
\ ale#test#GetLoclistWithoutModule()
|
||||
|
||||
Execute(LSP errors should mark linters no longer active):
|
||||
let b:ale_linters = ['pyls']
|
||||
runtime ale_linters/python/pyls.vim
|
|
@ -1,5 +1,6 @@
|
|||
Before:
|
||||
Save g:ale_max_buffer_history_size
|
||||
Save g:ale_history_enabled
|
||||
Save g:ale_history_log_output
|
||||
Save g:ale_run_synchronously
|
||||
Save g:ale_enabled
|
||||
|
@ -54,8 +55,6 @@ After:
|
|||
" Reset the shell back to what it was before.
|
||||
let &shell = g:current_shell
|
||||
unlet g:current_shell
|
||||
let g:ale_history_enabled = 1
|
||||
let g:ale_history_log_output = 0
|
||||
unlet g:history
|
||||
|
||||
call ale#engine#Cleanup(bufnr(''))
|
||||
|
|
|
@ -1,3 +1,11 @@
|
|||
Before:
|
||||
Save g:ale_disable_lsp
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
unlet! b:ale_disable_lsp
|
||||
|
||||
Execute(GetList should ignore some invalid values):
|
||||
AssertEqual [], ale#engine#ignore#GetList('', 'foo')
|
||||
AssertEqual [], ale#engine#ignore#GetList('', 0)
|
||||
|
@ -98,7 +106,6 @@ Execute(Exclude should handle Dictionaries):
|
|||
\ )
|
||||
|
||||
Execute(Exclude should filter LSP linters when g:ale_disable_lsp is set to 1):
|
||||
let g:ale_disable_lsp = 1
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {'name': 'linter1', 'aliases': [], 'lsp': ''},
|
||||
|
@ -116,7 +123,6 @@ Execute(Exclude should filter LSP linters when g:ale_disable_lsp is set to 1):
|
|||
\ )
|
||||
|
||||
Execute(Exclude should filter LSP linters when b:ale_disable_lsp is set to 1):
|
||||
let b:ale_disable_lsp = 1
|
||||
AssertEqual
|
||||
\ [
|
||||
\ {'name': 'linter1', 'aliases': [], 'lsp': ''},
|
||||
|
|
Reference in a new issue