mirror of
https://github.com/dense-analysis/ale.git
synced 2026-03-05 14:44:24 +08:00
fix: Use ALE to reliably find project options
This commit is contained in:
@@ -18,15 +18,42 @@ function! ale#fixers#astyle#Var(buffer, name) abort
|
|||||||
return ale#Var(a:buffer, l:ft . '_astyle_' . a:name)
|
return ale#Var(a:buffer, l:ft . '_astyle_' . a:name)
|
||||||
endfunction
|
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
|
function! ale#fixers#astyle#Fix(buffer) abort
|
||||||
let l:executable = ale#fixers#astyle#Var(a:buffer, 'executable')
|
let l:executable = ale#fixers#astyle#Var(a:buffer, 'executable')
|
||||||
let l:filename = ale#Escape(bufname(a:buffer))
|
let l:proj_options = ale#fixers#astyle#FindProjectOptions(a:buffer)
|
||||||
let l:options = ale#fixers#astyle#Var(a:buffer, 'project_options')
|
|
||||||
let l:command = ' --stdin='
|
let l:command = ' --stdin='
|
||||||
|
|
||||||
return {
|
return {
|
||||||
\ 'command': ale#Escape(l:executable)
|
\ 'command': ale#Escape(l:executable)
|
||||||
\ . (empty(l:options) ? '' : ' --project=' . l:options)
|
\ . (empty(l:proj_options) ? '' : ' --project=' . l:proj_options)
|
||||||
\ . l:command
|
\ . l:command
|
||||||
\}
|
\}
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -65,3 +65,14 @@ Execute(The astyle callback should return the correct default values with an opt
|
|||||||
\ . ' --stdin='
|
\ . ' --stdin='
|
||||||
\ },
|
\ },
|
||||||
\ ale#fixers#astyle#Fix(bufnr(''))
|
\ ale#fixers#astyle#Fix(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The astyle callback should find nearest default option file _astylrc):
|
||||||
|
call ale#test#SetFilename('../test_c_projects/makefile_project/subdir/file.c')
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ {
|
||||||
|
\ 'command': ale#Escape('xxxinvalid')
|
||||||
|
\ . ' --project=_astylerc'
|
||||||
|
\ . ' --stdin='
|
||||||
|
\ },
|
||||||
|
\ ale#fixers#astyle#Fix(bufnr(''))
|
||||||
|
|||||||
0
test/test_c_projects/makefile_project/_astylerc
Normal file
0
test/test_c_projects/makefile_project/_astylerc
Normal file
Reference in New Issue
Block a user