From e43e7065da17f45e4cce127a319ceee0a0311883 Mon Sep 17 00:00:00 2001 From: w0rp Date: Wed, 20 Dec 2017 12:20:38 +0000 Subject: Fix #1115 - Add support for wrapping all commands with an option --- autoload/ale/engine.vim | 2 +- autoload/ale/fix.vim | 2 +- autoload/ale/job.vim | 43 +++++++++++++++++++++++++++++++++++++------ autoload/ale/linter.vim | 2 ++ 4 files changed, 41 insertions(+), 8 deletions(-) (limited to 'autoload') diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index 8441ad16..70b5a3ba 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -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'), diff --git a/autoload/ale/fix.vim b/autoload/ale/fix.vim index 0a270ecc..62a4f9b1 100644 --- a/autoload/ale/fix.vim +++ b/autoload/ale/fix.vim @@ -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'), diff --git a/autoload/ale/job.vim b/autoload/ale/job.vim index e6a75c88..2e0b8ca2 100644 --- a/autoload/ale/job.vim +++ b/autoload/ale/job.vim @@ -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. diff --git a/autoload/ale/linter.vim b/autoload/ale/linter.vim index f4fa0c44..d059a12d 100644 --- a/autoload/ale/linter.vim +++ b/autoload/ale/linter.vim @@ -1,3 +1,4 @@ +call ale#Set('wrap_command_as_one_argument', 0) " Author: w0rp " 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( -- cgit v1.2.3