feat: Add project option file support for astyle

This commit is contained in:
jhlink 2020-07-26 21:11:37 -04:00
parent b25bb64a4d
commit 78295024e1
2 changed files with 31 additions and 0 deletions

View File

@ -4,6 +4,7 @@
function! s:set_variables() abort
for l:ft in ['c', 'cpp']
call ale#Set(l:ft . '_astyle_executable', 'astyle')
call ale#Set(l:ft . '_astyle_options', '')
endfor
endfunction
@ -19,9 +20,11 @@ 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, 'options')
let l:command = ' --stdin=' . l:filename
return {
\ 'command': ale#Escape(l:executable) . l:command
\ . (empty(l:options) ? '' : ' --project=' . l:options)
\}
endfunction

View File

@ -1,5 +1,6 @@
Before:
Save g:ale_c_astyle_executable
Save g:ale_c_astyle_options
" Use an invalid global executable, so we don't match it.
let g:ale_c_astyle_executable = 'xxxinvalid'
@ -35,3 +36,30 @@ Execute(The astyle callback should support cpp files):
\ },
\ ale#fixers#astyle#Fix(bufnr(''))
Execute(The astyle callback should support cpp files with option file set):
call ale#test#SetFilename('../cpp_files/dummy.cpp')
let g:ale_cpp_astyle_options = '.astylerc_cpp'
let targetfile = '/testplugin/test/cpp_files/dummy.cpp'
set filetype=cpp " The test fails without this
AssertEqual
\ {
\ 'command': ale#Escape('invalidpp')
\ . ' --stdin=' . ale#Escape(targetfile)
\ . ' --project=' . g:ale_cpp_astyle_options
\ },
\ ale#fixers#astyle#Fix(bufnr(''))
Execute(The astyle callback should return the correct default values with an option file set):
call ale#test#SetFilename('../c_files/testfile.c')
let targetfile = '/testplugin/test/c_files/testfile.c'
let g:ale_c_astyle_options = '.astylerc'
AssertEqual
\ {
\ 'command': ale#Escape('xxxinvalid')
\ . ' --stdin=' . ale#Escape(targetfile)
\ . ' --project=' . g:ale_c_astyle_options
\ },
\ ale#fixers#astyle#Fix(bufnr(''))