diff options
author | jhlink <jhlink@users.noreply.github.com> | 2020-07-29 01:36:45 -0400 |
---|---|---|
committer | jhlink <jhlink@users.noreply.github.com> | 2020-07-29 01:36:45 -0400 |
commit | 428c5f94dab423d4d1af0ef46d51999d2142e1eb (patch) | |
tree | 3197598dc66badbefc6b8afdc57e212d1fa2825b /autoload | |
parent | f4cff3bc06e35a1d5861972d9e1cea615255e989 (diff) | |
download | ale-428c5f94dab423d4d1af0ef46d51999d2142e1eb.zip |
fix: Use ALE to reliably find project options
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/fixers/astyle.vim | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/autoload/ale/fixers/astyle.vim b/autoload/ale/fixers/astyle.vim index ba4ddceb..0abceb10 100644 --- a/autoload/ale/fixers/astyle.vim +++ b/autoload/ale/fixers/astyle.vim @@ -18,15 +18,42 @@ function! ale#fixers#astyle#Var(buffer, name) abort return ale#Var(a:buffer, l:ft . '_astyle_' . a:name) endfunction +" Try to find a project options file. +function! ale#fixers#astyle#FindProjectOptions(buffer) abort + let l:proj_options = ale#fixers#astyle#Var(a:buffer, 'project_options') + + " If user has set project options variable then use it and skip any searching. + " This would allow users to use project files named differently than .astylerc. + if !empty(l:proj_options) + return l:proj_options + endif + + " Try to find nearest .astylerc file. + let l:proj_options = fnamemodify(ale#path#FindNearestFile(a:buffer, '.astylerc'), ':t') + + if !empty(l:proj_options) + return l:proj_options + endif + + " Try to find nearest _astylerc file. + let l:proj_options = fnamemodify(ale#path#FindNearestFile(a:buffer, '_astylerc'), ':t') + + if !empty(l:proj_options) + return l:proj_options + endif + + " If no project options file is found return an empty string. + return '' +endfunction + function! ale#fixers#astyle#Fix(buffer) abort let l:executable = ale#fixers#astyle#Var(a:buffer, 'executable') - let l:filename = ale#Escape(bufname(a:buffer)) - let l:options = ale#fixers#astyle#Var(a:buffer, 'project_options') + let l:proj_options = ale#fixers#astyle#FindProjectOptions(a:buffer) let l:command = ' --stdin=' return { \ 'command': ale#Escape(l:executable) - \ . (empty(l:options) ? '' : ' --project=' . l:options) + \ . (empty(l:proj_options) ? '' : ' --project=' . l:proj_options) \ . l:command \} endfunction |