Make ALEFix support arguments
This commit is contained in:
parent
f9ba3d924f
commit
a591b191db
@ -356,8 +356,11 @@ function! s:RunFixer(options) abort
|
|||||||
call ale#fix#ApplyFixes(l:buffer, l:input)
|
call ale#fix#ApplyFixes(l:buffer, l:input)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:GetCallbacks(linters) abort
|
||||||
function! s:GetCallbacks(buffer) abort
|
function! s:GetCallbacks(buffer) abort
|
||||||
if type(get(b:, 'ale_fixers')) is type([])
|
if len(a:linters)
|
||||||
|
let l:callback_list = a:linters
|
||||||
|
elseif type(get(b:, 'ale_fixers')) is type([])
|
||||||
" Lists can be used for buffer-local variables only
|
" Lists can be used for buffer-local variables only
|
||||||
let l:callback_list = b:ale_fixers
|
let l:callback_list = b:ale_fixers
|
||||||
else
|
else
|
||||||
@ -422,13 +425,13 @@ endfunction
|
|||||||
" Accepts an optional argument for what to do when fixing.
|
" 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.
|
" Returns 0 if no fixes can be applied, and 1 if fixing can be done.
|
||||||
function! ale#fix#Fix(buffer, fixing_flag) abort
|
function! ale#fix#Fix(buffer, fixing_flag, ...) abort
|
||||||
if a:fixing_flag isnot# '' && a:fixing_flag isnot# 'save_file'
|
if a:fixing_flag isnot# '' && a:fixing_flag isnot# 'save_file'
|
||||||
throw "fixing_flag must be either '' or 'save_file'"
|
throw "fixing_flag must be either '' or 'save_file'"
|
||||||
endif
|
endif
|
||||||
|
|
||||||
try
|
try
|
||||||
let l:callback_list = s:GetCallbacks(a:buffer)
|
let l:callback_list = s:GetCallbacks(a:buffer, a:000)
|
||||||
catch /E700\|BADNAME/
|
catch /E700\|BADNAME/
|
||||||
let l:function_name = join(split(split(v:exception, ':')[3]))
|
let l:function_name = join(split(split(v:exception, ':')[3]))
|
||||||
let l:echo_message = printf(
|
let l:echo_message = printf(
|
||||||
|
@ -277,6 +277,14 @@ function! s:ShouldSuggestForType(suggested_filetypes, type_list) abort
|
|||||||
return 0
|
return 0
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:IsGenericFixer(suggested_filetypes) abort
|
||||||
|
if empty(a:suggested_filetypes)
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
|
|
||||||
|
return 0
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:FormatEntry(key, entry) abort
|
function! s:FormatEntry(key, entry) abort
|
||||||
let l:aliases_str = ''
|
let l:aliases_str = ''
|
||||||
|
|
||||||
@ -296,6 +304,27 @@ function! s:FormatEntry(key, entry) abort
|
|||||||
\)
|
\)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Get list of applicable fixers for filetype, including generic fixers
|
||||||
|
function! ale#fix#registry#GetApplicableFixers(filetype) abort
|
||||||
|
let l:type_list = split(a:filetype, '\.')
|
||||||
|
let l:fixer_name_list = []
|
||||||
|
|
||||||
|
for l:key in sort(keys(s:entries))
|
||||||
|
let l:suggested_filetypes = s:entries[l:key].suggested_filetypes
|
||||||
|
|
||||||
|
if s:IsGenericFixer(l:suggested_filetypes) || s:ShouldSuggestForType(l:suggested_filetypes, l:type_list)
|
||||||
|
call add(l:fixer_name_list, l:key)
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
|
||||||
|
return l:fixer_name_list
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Function that returns autocomplete candidates for ALEFix command
|
||||||
|
function! ale#fix#registry#CompleteFixers(ArgLead, CmdLine, CursorPos) abort
|
||||||
|
return ale#fix#registry#GetApplicableFixers(&filetype)
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Suggest functions to use from the registry.
|
" Suggest functions to use from the registry.
|
||||||
function! ale#fix#registry#Suggest(filetype) abort
|
function! ale#fix#registry#Suggest(filetype) abort
|
||||||
let l:type_list = split(a:filetype, '\.')
|
let l:type_list = split(a:filetype, '\.')
|
||||||
@ -315,7 +344,7 @@ function! ale#fix#registry#Suggest(filetype) abort
|
|||||||
let l:generic_fixer_list = []
|
let l:generic_fixer_list = []
|
||||||
|
|
||||||
for l:key in sort(keys(s:entries))
|
for l:key in sort(keys(s:entries))
|
||||||
if empty(s:entries[l:key].suggested_filetypes)
|
if s:IsGenericFixer(s:entries[l:key].suggested_filetypes)
|
||||||
call add(
|
call add(
|
||||||
\ l:generic_fixer_list,
|
\ l:generic_fixer_list,
|
||||||
\ s:FormatEntry(l:key, s:entries[l:key]),
|
\ s:FormatEntry(l:key, s:entries[l:key]),
|
||||||
|
@ -263,7 +263,7 @@ command! -bar ALEInfoToClipboard :call ale#debugging#InfoToClipboard()
|
|||||||
command! -bar -nargs=1 ALEInfoToFile :call ale#debugging#InfoToFile(<f-args>)
|
command! -bar -nargs=1 ALEInfoToFile :call ale#debugging#InfoToFile(<f-args>)
|
||||||
|
|
||||||
" Fix problems in files.
|
" Fix problems in files.
|
||||||
command! -bar ALEFix :call ale#fix#Fix(bufnr(''), '')
|
command! -bar -nargs=* -complete=customlist,ale#fix#registry#CompleteFixers ALEFix :call ale#fix#Fix(bufnr(''), '', <f-args>)
|
||||||
" Suggest registered functions to use for fixing problems.
|
" Suggest registered functions to use for fixing problems.
|
||||||
command! -bar ALEFixSuggest :call ale#fix#registry#Suggest(&filetype)
|
command! -bar ALEFixSuggest :call ale#fix#registry#Suggest(&filetype)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user