#1501 Pass the buffer number from BufWritePost on to ale#fix#Fix

This commit is contained in:
w0rp 2018-04-13 20:59:05 +01:00
parent 56c7957a75
commit f5f3424fcf
No known key found for this signature in database
GPG Key ID: 0FC1ECAA8C81CD83
3 changed files with 12 additions and 20 deletions

View File

@ -19,7 +19,7 @@ function! ale#events#SaveEvent(buffer) abort
endif
if ale#Var(a:buffer, 'fix_on_save')
let l:will_fix = ale#fix#Fix('save_file')
let l:will_fix = ale#fix#Fix(a:buffer, 'save_file')
let l:should_lint = l:should_lint && !l:will_fix
endif

View File

@ -356,14 +356,14 @@ function! s:RunFixer(options) abort
call ale#fix#ApplyFixes(l:buffer, l:input)
endfunction
function! s:GetCallbacks() abort
function! s:GetCallbacks(buffer) abort
if type(get(b:, 'ale_fixers')) is type([])
" Lists can be used for buffer-local variables only
let l:callback_list = b:ale_fixers
else
" buffer and global options can use dictionaries mapping filetypes to
" callbacks to run.
let l:fixers = ale#Var(bufnr(''), 'fixers')
let l:fixers = ale#Var(a:buffer, 'fixers')
let l:callback_list = []
for l:sub_type in split(&filetype, '\.')
@ -422,19 +422,13 @@ endfunction
" Accepts an optional argument for what to do when fixing.
"
" Returns 0 if no fixes can be applied, and 1 if fixing can be done.
function! ale#fix#Fix(...) abort
if len(a:0) > 1
throw 'too many arguments!'
endif
let l:fixing_flag = get(a:000, 0, '')
if l:fixing_flag isnot# '' && l:fixing_flag isnot# 'save_file'
function! ale#fix#Fix(buffer, fixing_flag) abort
if a:fixing_flag isnot# '' && a:fixing_flag isnot# 'save_file'
throw "fixing_flag must be either '' or 'save_file'"
endif
try
let l:callback_list = s:GetCallbacks()
let l:callback_list = s:GetCallbacks(a:buffer)
catch /E700\|BADNAME/
let l:function_name = join(split(split(v:exception, ':')[3]))
let l:echo_message = printf(
@ -447,29 +441,27 @@ function! ale#fix#Fix(...) abort
endtry
if empty(l:callback_list)
if l:fixing_flag is# ''
if a:fixing_flag is# ''
execute 'echom ''No fixers have been defined. Try :ALEFixSuggest'''
endif
return 0
endif
let l:buffer = bufnr('')
for l:job_id in keys(s:job_info_map)
call remove(s:job_info_map, l:job_id)
call ale#job#Stop(l:job_id)
endfor
" Clean up any files we might have left behind from a previous run.
call ale#fix#RemoveManagedFiles(l:buffer)
call ale#fix#InitBufferData(l:buffer, l:fixing_flag)
call ale#fix#RemoveManagedFiles(a:buffer)
call ale#fix#InitBufferData(a:buffer, a:fixing_flag)
silent doautocmd <nomodeline> User ALEFixPre
call s:RunFixer({
\ 'buffer': l:buffer,
\ 'input': g:ale_fix_buffer_data[l:buffer].lines_before,
\ 'buffer': a:buffer,
\ 'input': g:ale_fix_buffer_data[a:buffer].lines_before,
\ 'callback_index': 0,
\ 'callback_list': l:callback_list,
\})

View File

@ -263,7 +263,7 @@ command! -bar ALEInfoToClipboard :call ale#debugging#InfoToClipboard()
command! -bar -nargs=1 ALEInfoToFile :call ale#debugging#InfoToFile(<f-args>)
" Fix problems in files.
command! -bar ALEFix :call ale#fix#Fix()
command! -bar ALEFix :call ale#fix#Fix(bufnr(''), '')
" Suggest registered functions to use for fixing problems.
command! -bar ALEFixSuggest :call ale#fix#registry#Suggest(&filetype)