summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--autoload/ale/command.vim6
-rw-r--r--autoload/ale/engine.vim5
-rw-r--r--autoload/ale/fix.vim6
-rw-r--r--autoload/ale/lsp_linter.vim2
-rw-r--r--test/test_format_command.vader59
5 files changed, 50 insertions, 28 deletions
diff --git a/autoload/ale/command.vim b/autoload/ale/command.vim
index 543c9953..6c56d518 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, executable, command, pipe_file_if_needed) abort
+function! ale#command#FormatCommand(buffer, executable, command, pipe_file_if_needed, CreateTemporaryFileForJob) abort
let l:temporary_file = ''
let l:command = a:command
@@ -58,5 +58,7 @@ function! ale#command#FormatCommand(buffer, executable, command, pipe_file_if_ne
let l:command = l:command . ' < ' . ale#Escape(l:temporary_file)
endif
- return [l:temporary_file, l:command]
+ let l:file_created = a:CreateTemporaryFileForJob(a:buffer, l:temporary_file)
+
+ return [l:temporary_file, l:command, l:file_created]
endfunction
diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim
index e1c8d93f..ace123dc 100644
--- a/autoload/ale/engine.vim
+++ b/autoload/ale/engine.vim
@@ -512,14 +512,15 @@ function! s:RunJob(options) abort
let l:read_buffer = a:options.read_buffer
let l:info = g:ale_buffer_info[l:buffer]
- let [l:temporary_file, l:command] = ale#command#FormatCommand(
+ let [l:temporary_file, l:command, l:file_created] = ale#command#FormatCommand(
\ l:buffer,
\ l:executable,
\ l:command,
\ l:read_buffer,
+ \ function('s:CreateTemporaryFileForJob'),
\)
- if s:CreateTemporaryFileForJob(l:buffer, l:temporary_file)
+ if l:file_created
" If a temporary filename has been formatted in to the command, then
" we do not need to send the Vim buffer to the command.
let l:read_buffer = 0
diff --git a/autoload/ale/fix.vim b/autoload/ale/fix.vim
index 423e85be..59502933 100644
--- a/autoload/ale/fix.vim
+++ b/autoload/ale/fix.vim
@@ -172,7 +172,7 @@ function! ale#fix#RemoveManagedFiles(buffer) abort
let g:ale_fix_buffer_data[a:buffer].temporary_directory_list = []
endfunction
-function! s:CreateTemporaryFileForJob(buffer, temporary_file, input) abort
+function! s:CreateTemporaryFileForJob(input, buffer, temporary_file) abort
if empty(a:temporary_file)
" There is no file, so we didn't create anything.
return 0
@@ -218,13 +218,13 @@ function! s:RunJob(options) abort
return 1
endif
- let [l:temporary_file, l:command] = ale#command#FormatCommand(
+ let [l:temporary_file, l:command, l:file_created] = ale#command#FormatCommand(
\ l:buffer,
\ '',
\ l:command,
\ l:read_buffer,
+ \ function('s:CreateTemporaryFileForJob', [l:input]),
\)
- call s:CreateTemporaryFileForJob(l:buffer, l:temporary_file, l:input)
let l:command = ale#job#PrepareCommand(l:buffer, l:command)
let l:job_options = {
diff --git a/autoload/ale/lsp_linter.vim b/autoload/ale/lsp_linter.vim
index 42d67398..d92dae7e 100644
--- a/autoload/ale/lsp_linter.vim
+++ b/autoload/ale/lsp_linter.vim
@@ -182,7 +182,7 @@ function! ale#lsp_linter#StartLSP(buffer, linter) abort
let l:command = ale#linter#GetCommand(a:buffer, a:linter)
" 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, {-> 0})[1]
let l:command = ale#job#PrepareCommand(a:buffer, l:command)
let l:ready = ale#lsp#StartProgram(l:conn_id, l:executable, l:command)
endif
diff --git a/test/test_format_command.vader b/test/test_format_command.vader
index 71285efa..119c7138 100644
--- a/test/test_format_command.vader
+++ b/test/test_format_command.vader
@@ -8,28 +8,38 @@ Before:
AssertEqual 'dummy.txt', fnamemodify(a:filename, ':t')
endfunction
+ function! TestCreateFunc(buffer, temporary_file) abort
+ return !empty(a:temporary_file)
+ endfunction
+
After:
unlet! g:result
unlet! g:match
delfunction CheckTempFile
+ delfunction TestCreateFunc
Execute(FormatCommand should do nothing to basic command strings):
- AssertEqual ['', 'awesome-linter do something'], ale#command#FormatCommand(bufnr('%'), '', 'awesome-linter do something', 0)
+ AssertEqual
+ \ ['', 'awesome-linter do something', 0],
+ \ ale#command#FormatCommand(bufnr('%'), '', 'awesome-linter do something', 0, function('TestCreateFunc'))
Execute(FormatCommand should handle %%, and ignore other percents):
- AssertEqual ['', '% %%d %%f %x %'], ale#command#FormatCommand(bufnr('%'), '', '%% %%%d %%%f %x %', 0)
+ AssertEqual
+ \ ['', '% %%d %%f %x %', 0],
+ \ ale#command#FormatCommand(bufnr('%'), '', '%% %%%d %%%f %x %', 0, function('TestCreateFunc'))
Execute(FormatCommand should convert %s to the current filename):
AssertEqual
\ [
\ '',
- \ 'foo ' . ale#Escape(expand('%:p')) . ' bar ' . ale#Escape(expand('%:p'))
+ \ 'foo ' . ale#Escape(expand('%:p')) . ' bar ' . ale#Escape(expand('%:p')),
+ \ 0,
\ ],
- \ ale#command#FormatCommand(bufnr('%'), '', 'foo %s bar %s', 0)
+ \ ale#command#FormatCommand(bufnr('%'), '', 'foo %s bar %s', 0, function('TestCreateFunc'))
Execute(FormatCommand should convert %t to a new temporary filename):
- let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %t', 0)
+ let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %t', 0, function('TestCreateFunc'))
call CheckTempFile(g:result[0])
@@ -42,8 +52,17 @@ Execute(FormatCommand should convert %t to a new temporary filename):
" The two temporary filenames formatted in should be the same.
AssertEqual g:match[1], g:match[2]
+Execute(FormatCommand should signal that files are created when temporary files are needed):
+ AssertEqual
+ \ 1,
+ \ ale#command#FormatCommand(bufnr('%'), '', 'foo %t', 0, function('TestCreateFunc'))[2]
+
+ AssertEqual
+ \ 0,
+ \ ale#command#FormatCommand(bufnr('%'), '', 'foo %s', 0, function('TestCreateFunc'))[2]
+
Execute(FormatCommand should let you combine %s and %t):
- let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %s', 0)
+ let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo %t bar %s', 0, function('TestCreateFunc'))
call CheckTempFile(g:result[0])
@@ -59,31 +78,31 @@ Execute(FormatCommand should let you combine %s and %t):
Execute(FormatCommand should replace %e with the escaped executable):
if has('win32')
AssertEqual
- \ ['', 'foo foo'],
- \ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0)
+ \ ['', 'foo foo', 0],
+ \ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, function('TestCreateFunc'))
AssertEqual
- \ ['', '"foo bar"'],
- \ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0)
+ \ ['', '"foo bar"', 0],
+ \ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, function('TestCreateFunc'))
AssertEqual
- \ ['', '%e %e'],
- \ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0)
+ \ ['', '%e %e', 0],
+ \ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, function('TestCreateFunc'))
else
AssertEqual
- \ ['', '''foo'' ''foo'''],
- \ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0)
+ \ ['', '''foo'' ''foo''', 0],
+ \ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, function('TestCreateFunc'))
AssertEqual
- \ ['', '''foo bar'''],
- \ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0)
+ \ ['', '''foo bar''', 0],
+ \ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, function('TestCreateFunc'))
AssertEqual
- \ ['', '%e %e'],
- \ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0)
+ \ ['', '%e %e', 0],
+ \ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, function('TestCreateFunc'))
endif
Execute(EscapeCommandPart should escape all percent signs):
AssertEqual '%%s %%t %%%% %%s %%t %%%%', ale#engine#EscapeCommandPart('%s %t %% %s %t %%')
Execute(EscapeCommandPart should pipe in temporary files appropriately):
- let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar', 1)
+ let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar', 1, function('TestCreateFunc'))
call CheckTempFile(g:result[0])
@@ -91,7 +110,7 @@ Execute(EscapeCommandPart should pipe in temporary files appropriately):
Assert !empty(g:match), 'No match found! Result was: ' . g:result[1]
AssertEqual ale#Escape(g:result[0]), g:match[1]
- let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar %t', 1)
+ let g:result = ale#command#FormatCommand(bufnr('%'), '', 'foo bar %t', 1, function('TestCreateFunc'))
call CheckTempFile(g:result[0])