Fix #1115 - Add support for wrapping all commands with an option
This commit is contained in:
parent
2495744fc3
commit
e43e7065da
9 changed files with 148 additions and 30 deletions
|
@ -512,7 +512,7 @@ function! s:RunJob(options) abort
|
|||
endif
|
||||
endif
|
||||
|
||||
let l:command = ale#job#PrepareCommand(l:command)
|
||||
let l:command = ale#job#PrepareCommand(l:buffer, l:command)
|
||||
let l:job_options = {
|
||||
\ 'mode': 'nl',
|
||||
\ 'exit_cb': function('s:HandleExit'),
|
||||
|
|
|
@ -222,7 +222,7 @@ function! s:RunJob(options) abort
|
|||
\)
|
||||
call s:CreateTemporaryFileForJob(l:buffer, l:temporary_file, l:input)
|
||||
|
||||
let l:command = ale#job#PrepareCommand(l:command)
|
||||
let l:command = ale#job#PrepareCommand(l:buffer, l:command)
|
||||
let l:job_options = {
|
||||
\ 'mode': 'nl',
|
||||
\ 'exit_cb': function('s:HandleExit'),
|
||||
|
|
|
@ -165,23 +165,54 @@ function! ale#job#ValidateArguments(command, options) abort
|
|||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#job#PrepareCommand(command) abort
|
||||
function! s:PrepareWrappedCommand(original_wrapper, command) abort
|
||||
let l:match = matchlist(a:command, '\v^(.*(\&\&|;)) *(.*)$')
|
||||
let l:prefix = ''
|
||||
let l:command = a:command
|
||||
|
||||
if !empty(l:match)
|
||||
let l:prefix = l:match[1] . ' '
|
||||
let l:command = l:match[3]
|
||||
endif
|
||||
|
||||
let l:format = a:original_wrapper
|
||||
|
||||
if l:format =~# '%@'
|
||||
let l:wrapped = substitute(l:format, '%@', ale#Escape(l:command), '')
|
||||
else
|
||||
if l:format !~# '%\*'
|
||||
let l:format .= ' %*'
|
||||
endif
|
||||
|
||||
let l:wrapped = substitute(l:format, '%\*', l:command, '')
|
||||
endif
|
||||
|
||||
return l:prefix . l:wrapped
|
||||
endfunction
|
||||
|
||||
function! ale#job#PrepareCommand(buffer, command) abort
|
||||
let l:wrapper = ale#Var(a:buffer, 'command_wrapper')
|
||||
|
||||
let l:command = !empty(l:wrapper)
|
||||
\ ? s:PrepareWrappedCommand(l:wrapper, a:command)
|
||||
\ : a:command
|
||||
|
||||
" The command will be executed in a subshell. This fixes a number of
|
||||
" issues, including reading the PATH variables correctly, %PATHEXT%
|
||||
" expansion on Windows, etc.
|
||||
"
|
||||
" NeoVim handles this issue automatically if the command is a String,
|
||||
" but we'll do this explicitly, so we use thes same exact command for both
|
||||
" but we'll do this explicitly, so we use the same exact command for both
|
||||
" versions.
|
||||
if ale#Has('win32')
|
||||
return 'cmd /c ' . a:command
|
||||
if has('win32')
|
||||
return 'cmd /c ' . l:command
|
||||
endif
|
||||
|
||||
if &shell =~? 'fish$'
|
||||
return ['/bin/sh', '-c', a:command]
|
||||
return ['/bin/sh', '-c', l:command]
|
||||
endif
|
||||
|
||||
return split(&shell) + split(&shellcmdflag) + [a:command]
|
||||
return split(&shell) + split(&shellcmdflag) + [l:command]
|
||||
endfunction
|
||||
|
||||
" Start a job with options which are agnostic to Vim and NeoVim.
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
call ale#Set('wrap_command_as_one_argument', 0)
|
||||
" Author: w0rp <devw0rp@gmail.com>
|
||||
" Description: Linter registration and lazy-loading
|
||||
" Retrieves linters as requested by the engine, loading them if needed.
|
||||
|
@ -432,6 +433,7 @@ function! ale#linter#StartLSP(buffer, linter, callback) abort
|
|||
endif
|
||||
|
||||
let l:command = ale#job#PrepareCommand(
|
||||
\ a:buffer,
|
||||
\ ale#linter#GetCommand(a:buffer, a:linter),
|
||||
\)
|
||||
let l:conn_id = ale#lsp#StartProgram(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue