Fix #3183 - Escape filename characters from LSP/tsserver
This commit is contained in:
parent
152b2cb691
commit
5bc49d2047
2 changed files with 56 additions and 12 deletions
|
@ -34,7 +34,11 @@ 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:escaped_name = escape(
|
||||
\ fnameescape(l:filename),
|
||||
\ has('win32') ? '^' : '^,}]'
|
||||
\)
|
||||
let l:buffer = bufnr('^' . l:escaped_name . '$')
|
||||
let l:info = get(g:ale_buffer_info, l:buffer, {})
|
||||
|
||||
if empty(l:info)
|
||||
|
@ -52,7 +56,11 @@ endfunction
|
|||
|
||||
function! s:HandleTSServerDiagnostics(response, error_type) abort
|
||||
let l:linter_name = 'tsserver'
|
||||
let l:buffer = bufnr('^' . a:response.body.file . '$')
|
||||
let l:escaped_name = escape(
|
||||
\ fnameescape(a:response.body.file),
|
||||
\ has('win32') ? '^' : '^,}]'
|
||||
\)
|
||||
let l:buffer = bufnr('^' . l:escaped_name . '$')
|
||||
let l:info = get(g:ale_buffer_info, l:buffer, {})
|
||||
|
||||
if empty(l:info)
|
||||
|
|
|
@ -44,9 +44,21 @@ After:
|
|||
Given foobar(An empty file):
|
||||
Execute(tsserver syntax error responses should be handled correctly):
|
||||
runtime ale_linters/typescript/tsserver.vim
|
||||
call ale#test#SetFilename('filename.ts')
|
||||
|
||||
if has('win32')
|
||||
call ale#test#SetFilename('filename,[]^$.ts')
|
||||
else
|
||||
call ale#test#SetFilename('filename*?,{}[]^$.ts')
|
||||
endif
|
||||
|
||||
call ale#engine#InitBufferInfo(bufnr(''))
|
||||
|
||||
if has('win32')
|
||||
AssertEqual 'filename,[]^$.ts', expand('%:p:t')
|
||||
else
|
||||
AssertEqual 'filename*?,{}[]^$.ts', expand('%:p:t')
|
||||
endif
|
||||
|
||||
" When we get syntax errors and no semantic errors, we should keep the
|
||||
" syntax errors.
|
||||
call ale#lsp_linter#HandleLSPResponse(1, {
|
||||
|
@ -54,7 +66,7 @@ Execute(tsserver syntax error responses should be handled correctly):
|
|||
\ 'type': 'event',
|
||||
\ 'event': 'syntaxDiag',
|
||||
\ 'body': {
|
||||
\ 'file': g:dir . '/filename.ts',
|
||||
\ 'file': expand('%:p'),
|
||||
\ 'diagnostics':[
|
||||
\ {
|
||||
\ 'start': {
|
||||
|
@ -76,7 +88,7 @@ Execute(tsserver syntax error responses should be handled correctly):
|
|||
\ 'type': 'event',
|
||||
\ 'event': 'semanticDiag',
|
||||
\ 'body': {
|
||||
\ 'file': g:dir . '/filename.ts',
|
||||
\ 'file': expand('%:p'),
|
||||
\ 'diagnostics':[
|
||||
\ ],
|
||||
\ },
|
||||
|
@ -104,7 +116,7 @@ Execute(tsserver syntax error responses should be handled correctly):
|
|||
\ 'type': 'event',
|
||||
\ 'event': 'syntaxDiag',
|
||||
\ 'body': {
|
||||
\ 'file': g:dir . '/filename.ts',
|
||||
\ 'file': expand('%:p'),
|
||||
\ 'diagnostics':[
|
||||
\ ],
|
||||
\ },
|
||||
|
@ -146,9 +158,21 @@ Execute(tsserver syntax error responses should be handled correctly):
|
|||
|
||||
Execute(tsserver semantic error responses should be handled correctly):
|
||||
runtime ale_linters/typescript/tsserver.vim
|
||||
call ale#test#SetFilename('filename.ts')
|
||||
|
||||
if has('win32')
|
||||
call ale#test#SetFilename('filename,[]^$.ts')
|
||||
else
|
||||
call ale#test#SetFilename('filename*?,{}[]^$.ts')
|
||||
endif
|
||||
|
||||
call ale#engine#InitBufferInfo(bufnr(''))
|
||||
|
||||
if has('win32')
|
||||
AssertEqual 'filename,[]^$.ts', expand('%:p:t')
|
||||
else
|
||||
AssertEqual 'filename*?,{}[]^$.ts', expand('%:p:t')
|
||||
endif
|
||||
|
||||
" When we get syntax errors and no semantic errors, we should keep the
|
||||
" syntax errors.
|
||||
call ale#lsp_linter#HandleLSPResponse(1, {
|
||||
|
@ -156,7 +180,7 @@ Execute(tsserver semantic error responses should be handled correctly):
|
|||
\ 'type': 'event',
|
||||
\ 'event': 'syntaxDiag',
|
||||
\ 'body': {
|
||||
\ 'file': g:dir . '/filename.ts',
|
||||
\ 'file': expand('%:p'),
|
||||
\ 'diagnostics':[
|
||||
\ ],
|
||||
\ },
|
||||
|
@ -166,7 +190,7 @@ Execute(tsserver semantic error responses should be handled correctly):
|
|||
\ 'type': 'event',
|
||||
\ 'event': 'semanticDiag',
|
||||
\ 'body': {
|
||||
\ 'file': g:dir . '/filename.ts',
|
||||
\ 'file': expand('%:p'),
|
||||
\ 'diagnostics':[
|
||||
\ {
|
||||
\ 'start': {
|
||||
|
@ -206,7 +230,7 @@ Execute(tsserver semantic error responses should be handled correctly):
|
|||
\ 'type': 'event',
|
||||
\ 'event': 'semanticDiag',
|
||||
\ 'body': {
|
||||
\ 'file': g:dir . '/filename.ts',
|
||||
\ 'file': expand('%:p'),
|
||||
\ 'diagnostics':[
|
||||
\ ],
|
||||
\ },
|
||||
|
@ -270,15 +294,27 @@ Execute(tsserver errors should mark tsserver no longer active):
|
|||
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')
|
||||
|
||||
if has('win32')
|
||||
call ale#test#SetFilename('filename,[]^$.ts')
|
||||
else
|
||||
call ale#test#SetFilename('filename*?,{}[]^$.java')
|
||||
endif
|
||||
|
||||
call ale#engine#InitBufferInfo(bufnr(''))
|
||||
call ale#lsp_linter#SetLSPLinterMap({'1': 'eclipselsp'})
|
||||
|
||||
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',
|
||||
\ 'method':'textDocument/publishDiagnostics',
|
||||
\ 'params': {
|
||||
\ 'uri':'file://' . g:dir . '/filename.java',
|
||||
\ 'uri': ale#path#ToURI(expand('%:p')),
|
||||
\ 'diagnostics': [
|
||||
\ {
|
||||
\ 'range': {
|
||||
|
|
Reference in a new issue