Support formatting escaped executable names into commands with %e

This commit is contained in:
w0rp
2018-07-05 20:56:31 +01:00
parent f002c2c9f0
commit da692b2e2d
6 changed files with 68 additions and 19 deletions

View File

@@ -20,7 +20,7 @@ endfunction
" %s -> with the current filename
" %t -> with the name of an unused file in a temporary directory
" %% -> with a literal %
function! ale#command#FormatCommand(buffer, command, pipe_file_if_needed) abort
function! ale#command#FormatCommand(buffer, executable, command, pipe_file_if_needed) abort
let l:temporary_file = ''
let l:command = a:command
@@ -28,6 +28,11 @@ function! ale#command#FormatCommand(buffer, command, pipe_file_if_needed) abort
" with an ugly string.
let l:command = substitute(l:command, '%%', '<<PERCENTS>>', 'g')
" Replace %e with the escaped executable, if available.
if !empty(a:executable) && l:command =~# '%e'
let l:command = substitute(l:command, '%e', '\=ale#Escape(a:executable)', 'g')
endif
" Replace all %s occurrences in the string with the name of the current
" file.
if l:command =~# '%s'

View File

@@ -189,6 +189,7 @@ function! s:HandleExit(job_id, exit_code) abort
let l:linter = l:job_info.linter
let l:output = l:job_info.output
let l:buffer = l:job_info.buffer
let l:executable = l:job_info.executable
let l:next_chain_index = l:job_info.next_chain_index
if g:ale_history_enabled
@@ -212,7 +213,7 @@ function! s:HandleExit(job_id, exit_code) abort
endif
if l:next_chain_index < len(get(l:linter, 'command_chain', []))
call s:InvokeChain(l:buffer, l:linter, l:next_chain_index, l:output)
call s:InvokeChain(l:buffer, l:executable, l:linter, l:next_chain_index, l:output)
return
endif
@@ -440,6 +441,12 @@ endfunction
" Returns 1 when the job was started successfully.
function! s:RunJob(options) abort
let l:command = a:options.command
if empty(l:command)
return 0
endif
let l:executable = a:options.executable
let l:buffer = a:options.buffer
let l:linter = a:options.linter
let l:output_stream = a:options.output_stream
@@ -447,11 +454,12 @@ function! s:RunJob(options) abort
let l:read_buffer = a:options.read_buffer
let l:info = g:ale_buffer_info[l:buffer]
if empty(l:command)
return 0
endif
let [l:temporary_file, l:command] = ale#command#FormatCommand(l:buffer, l:command, l:read_buffer)
let [l:temporary_file, l:command] = ale#command#FormatCommand(
\ l:buffer,
\ l:executable,
\ l:command,
\ l:read_buffer,
\)
if s:CreateTemporaryFileForJob(l:buffer, l:temporary_file)
" If a temporary filename has been formatted in to the command, then
@@ -512,6 +520,7 @@ function! s:RunJob(options) abort
let s:job_info_map[l:job_id] = {
\ 'linter': l:linter,
\ 'buffer': l:buffer,
\ 'executable': l:executable,
\ 'output': [],
\ 'next_chain_index': l:next_chain_index,
\}
@@ -604,8 +613,9 @@ function! ale#engine#ProcessChain(buffer, linter, chain_index, input) abort
\}
endfunction
function! s:InvokeChain(buffer, linter, chain_index, input) abort
function! s:InvokeChain(buffer, executable, linter, chain_index, input) abort
let l:options = ale#engine#ProcessChain(a:buffer, a:linter, a:chain_index, a:input)
let l:options.executable = a:executable
return s:RunJob(l:options)
endfunction
@@ -699,7 +709,7 @@ function! s:RunLinter(buffer, linter) abort
let l:executable = ale#linter#GetExecutable(a:buffer, a:linter)
if ale#engine#IsExecutable(a:buffer, l:executable)
return s:InvokeChain(a:buffer, a:linter, 0, [])
return s:InvokeChain(a:buffer, l:executable, a:linter, 0, [])
endif
endif

View File

@@ -212,6 +212,7 @@ function! s:RunJob(options) abort
let [l:temporary_file, l:command] = ale#command#FormatCommand(
\ l:buffer,
\ '',
\ l:command,
\ l:read_buffer,
\)

View File

@@ -151,6 +151,8 @@ function! ale#lsp_linter#StartLSP(buffer, linter, callback) abort
return {}
endif
" 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#job#PrepareCommand(
\ a:buffer,
\ ale#linter#GetCommand(a:buffer, a:linter),