From 0b743389e526caa7c9065405917da84f83a59b17 Mon Sep 17 00:00:00 2001 From: w0rp Date: Thu, 18 May 2017 17:50:20 +0100 Subject: Send modified lines to jobs, not the file contents --- autoload/ale/fix.vim | 8 +++++--- test/test_ale_fix.vader | 10 ++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/autoload/ale/fix.vim b/autoload/ale/fix.vim index 70a36edc..288919aa 100644 --- a/autoload/ale/fix.vim +++ b/autoload/ale/fix.vim @@ -94,7 +94,7 @@ function! ale#fix#RemoveManagedFiles(buffer) abort let s:buffer_data[a:buffer].temporary_directory_list = [] endfunction -function! s:CreateTemporaryFileForJob(buffer, temporary_file) abort +function! s:CreateTemporaryFileForJob(buffer, temporary_file, input) abort if empty(a:temporary_file) " There is no file, so we didn't create anything. return 0 @@ -107,7 +107,7 @@ function! s:CreateTemporaryFileForJob(buffer, temporary_file) abort " Automatically delete the directory later. call ale#fix#ManageDirectory(a:buffer, l:temporary_directory) " Write the buffer out to a file. - call writefile(getbufline(a:buffer, 1, '$'), a:temporary_file) + call writefile(a:input, a:temporary_file) return 1 endfunction @@ -115,11 +115,12 @@ endfunction function! s:RunJob(options) abort let l:buffer = a:options.buffer let l:command = a:options.command + let l:input = a:options.input let l:output_stream = a:options.output_stream let l:read_temporary_file = a:options.read_temporary_file let [l:temporary_file, l:command] = ale#command#FormatCommand(l:buffer, l:command, 1) - call s:CreateTemporaryFileForJob(l:buffer, l:temporary_file) + call s:CreateTemporaryFileForJob(l:buffer, l:temporary_file, l:input) let l:command = ale#job#PrepareCommand(l:command) let l:job_options = { @@ -202,6 +203,7 @@ function! s:RunFixer(options) abort let l:job_ran = s:RunJob({ \ 'buffer': l:buffer, \ 'command': l:result.command, + \ 'input': l:input, \ 'output_stream': get(l:result, 'output_stream', 'stdout'), \ 'read_temporary_file': get(l:result, 'read_temporary_file', 0), \ 'callback_list': a:options.callback_list, diff --git a/test/test_ale_fix.vader b/test/test_ale_fix.vader index 95a37c6b..8ec7896d 100644 --- a/test/test_ale_fix.vader +++ b/test/test_ale_fix.vader @@ -98,6 +98,16 @@ Execute(ALEFix should allow jobs and simple functions to be combined): Expect(The lines from the temporary file should be modified): $x +Execute(ALEFix should send lines modified by functions to jobs): + let g:ale_fixers.testft = ['AddDollars', 'CatLine'] + ALEFix + +Expect(The lines should first be modified by the function, then the job): + $a + $b + $c + d + Execute(ALEFix should skip commands when jobs fail to run): let g:ale_emulate_job_failure = 1 let g:ale_fixers.testft = ['CatLine', 'AddDollars'] -- cgit v1.2.3