From da692b2e2dd9bc81047449b8811ab2672004b8bc Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 5 Jul 2018 20:56:31 +0100 Subject: Support formatting escaped executable names into commands with %e --- autoload/ale/command.vim | 7 ++++++- autoload/ale/engine.vim | 26 ++++++++++++++++++-------- autoload/ale/fix.vim | 1 + autoload/ale/lsp_linter.vim | 2 ++ 4 files changed, 27 insertions(+), 9 deletions(-) (limited to 'autoload') diff --git a/autoload/ale/command.vim b/autoload/ale/command.vim index 558fe233..b4bf3794 100644 --- a/autoload/ale/command.vim +++ b/autoload/ale/command.vim @@ -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, '%%', '<>', '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' diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index d97b6937..a64d8f9f 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -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 diff --git a/autoload/ale/fix.vim b/autoload/ale/fix.vim index 6e5875f6..62674b87 100644 --- a/autoload/ale/fix.vim +++ b/autoload/ale/fix.vim @@ -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, \) diff --git a/autoload/ale/lsp_linter.vim b/autoload/ale/lsp_linter.vim index 9e72362b..4527c74e 100644 --- a/autoload/ale/lsp_linter.vim +++ b/autoload/ale/lsp_linter.vim @@ -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), -- cgit v1.2.3