Fix command formatting for LSP linters

This commit is contained in:
w0rp 2018-07-05 21:48:47 +01:00
parent da692b2e2d
commit d5b4f6f7e7
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
2 changed files with 40 additions and 5 deletions

View File

@ -147,16 +147,14 @@ function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort
else else
let l:executable = ale#linter#GetExecutable(a:buffer, a:linter) let l:executable = ale#linter#GetExecutable(a:buffer, a:linter)
if !executable(l:executable) if empty(l:executable) || !executable(l:executable)
return {} return {}
endif endif
let l:command = ale#linter#GetCommand(a:buffer, a:linter)
" Format the command, so %e can be formatted into it. " Format the command, so %e can be formatted into it.
let l:command = ale#command#FormatCommand(a:buffer, l:executable, l:command, 0)[1] let l:command = ale#command#FormatCommand(a:buffer, l:executable, l:command, 0)[1]
let l:command = ale#job#PrepareCommand( let l:command = ale#job#PrepareCommand(a:buffer, l:command)
\ a:buffer,
\ ale#linter#GetCommand(a:buffer, a:linter),
\)
let l:conn_id = ale#lsp#StartProgram( let l:conn_id = ale#lsp#StartProgram(
\ l:executable, \ l:executable,
\ l:command, \ l:command,

View File

@ -0,0 +1,37 @@
Before:
runtime autoload/ale/lsp.vim
let g:args = []
" Mock the StartProgram function so we can just capture the arguments.
function! ale#lsp#StartProgram(...) abort
let g:args = a:000
endfunction
After:
unlet! g:args
runtime autoload/ale/lsp.vim
Execute(Command formatting should be applied correctly for LSP linters):
call ale#lsp_linter#StartLSP(
\ bufnr(''),
\ {
\ 'language_callback': {-> 'x'},
\ 'project_root_callback': {-> '/foo/bar'},
\ 'lsp': 'stdio',
\ 'executable': has('win32') ? 'cmd': 'true',
\ 'command': '%e --foo',
\ },
\ {->0}
\)
if has('win32')
AssertEqual
\ ['true', 'cmd /s/c cmd --foo', '/foo/bar'],
\ g:args[:2]
else
AssertEqual
\ ['true', ['/bin/bash', '-c', '''true'' --foo'], '/foo/bar'],
\ g:args[:2]
endif