mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-07 21:24:33 +08:00
#2132 Move CreateTemporaryFileForJob calls into FormatCommand
This commit is contained in:
@@ -20,7 +20,7 @@ endfunction
|
|||||||
" %s -> with the current filename
|
" %s -> with the current filename
|
||||||
" %t -> with the name of an unused file in a temporary directory
|
" %t -> with the name of an unused file in a temporary directory
|
||||||
" %% -> with a literal %
|
" %% -> 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:temporary_file = ''
|
||||||
let l:command = a:command
|
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)
|
let l:command = l:command . ' < ' . ale#Escape(l:temporary_file)
|
||||||
endif
|
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
|
endfunction
|
||||||
|
|||||||
@@ -512,14 +512,15 @@ function! s:RunJob(options) abort
|
|||||||
let l:read_buffer = a:options.read_buffer
|
let l:read_buffer = a:options.read_buffer
|
||||||
let l:info = g:ale_buffer_info[l: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:buffer,
|
||||||
\ l:executable,
|
\ l:executable,
|
||||||
\ l:command,
|
\ l:command,
|
||||||
\ l:read_buffer,
|
\ 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
|
" If a temporary filename has been formatted in to the command, then
|
||||||
" we do not need to send the Vim buffer to the command.
|
" we do not need to send the Vim buffer to the command.
|
||||||
let l:read_buffer = 0
|
let l:read_buffer = 0
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ function! ale#fix#RemoveManagedFiles(buffer) abort
|
|||||||
let g:ale_fix_buffer_data[a:buffer].temporary_directory_list = []
|
let g:ale_fix_buffer_data[a:buffer].temporary_directory_list = []
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:CreateTemporaryFileForJob(buffer, temporary_file, input) abort
|
function! s:CreateTemporaryFileForJob(input, buffer, temporary_file) abort
|
||||||
if empty(a:temporary_file)
|
if empty(a:temporary_file)
|
||||||
" There is no file, so we didn't create anything.
|
" There is no file, so we didn't create anything.
|
||||||
return 0
|
return 0
|
||||||
@@ -218,13 +218,13 @@ function! s:RunJob(options) abort
|
|||||||
return 1
|
return 1
|
||||||
endif
|
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:buffer,
|
||||||
\ '',
|
\ '',
|
||||||
\ l:command,
|
\ l:command,
|
||||||
\ l:read_buffer,
|
\ 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:command = ale#job#PrepareCommand(l:buffer, l:command)
|
||||||
let l:job_options = {
|
let l:job_options = {
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ function! ale#lsp_linter#StartLSP(buffer, linter) abort
|
|||||||
|
|
||||||
let l:command = ale#linter#GetCommand(a:buffer, a:linter)
|
let l:command = ale#linter#GetCommand(a:buffer, a:linter)
|
||||||
" Format the command, so %e can be formatted into it.
|
" 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:command = ale#job#PrepareCommand(a:buffer, l:command)
|
||||||
let l:ready = ale#lsp#StartProgram(l:conn_id, l:executable, l:command)
|
let l:ready = ale#lsp#StartProgram(l:conn_id, l:executable, l:command)
|
||||||
endif
|
endif
|
||||||
|
|||||||
@@ -8,28 +8,38 @@ Before:
|
|||||||
AssertEqual 'dummy.txt', fnamemodify(a:filename, ':t')
|
AssertEqual 'dummy.txt', fnamemodify(a:filename, ':t')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! TestCreateFunc(buffer, temporary_file) abort
|
||||||
|
return !empty(a:temporary_file)
|
||||||
|
endfunction
|
||||||
|
|
||||||
After:
|
After:
|
||||||
unlet! g:result
|
unlet! g:result
|
||||||
unlet! g:match
|
unlet! g:match
|
||||||
|
|
||||||
delfunction CheckTempFile
|
delfunction CheckTempFile
|
||||||
|
delfunction TestCreateFunc
|
||||||
|
|
||||||
Execute(FormatCommand should do nothing to basic command strings):
|
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):
|
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):
|
Execute(FormatCommand should convert %s to the current filename):
|
||||||
AssertEqual
|
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):
|
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])
|
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.
|
" The two temporary filenames formatted in should be the same.
|
||||||
AssertEqual g:match[1], g:match[2]
|
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):
|
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])
|
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):
|
Execute(FormatCommand should replace %e with the escaped executable):
|
||||||
if has('win32')
|
if has('win32')
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ ['', 'foo foo'],
|
\ ['', 'foo foo', 0],
|
||||||
\ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0)
|
\ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, function('TestCreateFunc'))
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ ['', '"foo bar"'],
|
\ ['', '"foo bar"', 0],
|
||||||
\ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0)
|
\ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, function('TestCreateFunc'))
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ ['', '%e %e'],
|
\ ['', '%e %e', 0],
|
||||||
\ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0)
|
\ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, function('TestCreateFunc'))
|
||||||
else
|
else
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ ['', '''foo'' ''foo'''],
|
\ ['', '''foo'' ''foo''', 0],
|
||||||
\ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0)
|
\ ale#command#FormatCommand(bufnr('%'), 'foo', '%e %e', 0, function('TestCreateFunc'))
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ ['', '''foo bar'''],
|
\ ['', '''foo bar''', 0],
|
||||||
\ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0)
|
\ ale#command#FormatCommand(bufnr('%'), 'foo bar', '%e', 0, function('TestCreateFunc'))
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ ['', '%e %e'],
|
\ ['', '%e %e', 0],
|
||||||
\ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0)
|
\ ale#command#FormatCommand(bufnr('%'), '', '%e %e', 0, function('TestCreateFunc'))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
Execute(EscapeCommandPart should escape all percent signs):
|
Execute(EscapeCommandPart should escape all percent signs):
|
||||||
AssertEqual '%%s %%t %%%% %%s %%t %%%%', ale#engine#EscapeCommandPart('%s %t %% %s %t %%')
|
AssertEqual '%%s %%t %%%% %%s %%t %%%%', ale#engine#EscapeCommandPart('%s %t %% %s %t %%')
|
||||||
|
|
||||||
Execute(EscapeCommandPart should pipe in temporary files appropriately):
|
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])
|
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]
|
Assert !empty(g:match), 'No match found! Result was: ' . g:result[1]
|
||||||
AssertEqual ale#Escape(g:result[0]), g:match[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])
|
call CheckTempFile(g:result[0])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user