diff --git a/autoload/ale/fixers/ormolu.vim b/autoload/ale/fixers/ormolu.vim index 69b55c1f12..993de4f873 100644 --- a/autoload/ale/fixers/ormolu.vim +++ b/autoload/ale/fixers/ormolu.vim @@ -1,12 +1,34 @@ call ale#Set('haskell_ormolu_executable', 'ormolu') call ale#Set('haskell_ormolu_options', '') -function! ale#fixers#ormolu#Fix(buffer) abort +function! ale#fixers#ormolu#GetExecutable(buffer) abort let l:executable = ale#Var(a:buffer, 'haskell_ormolu_executable') + + return ale#handlers#haskell_stack#EscapeExecutable(l:executable, 'ormolu') +endfunction + +function! ale#fixers#ormolu#ApplyFixForVersion(buffer, version) abort + let l:executable = ale#fixers#ormolu#GetExecutable(a:buffer) let l:options = ale#Var(a:buffer, 'haskell_ormolu_options') + if ale#semver#GTE(a:version, [0, 8, 0]) + let l:args = ' --stdin-input-file %s' + else + let l:args = ' %s' + endif + return { - \ 'command': ale#Escape(l:executable) - \ . (empty(l:options) ? '' : ' ' . l:options), + \ 'command': l:executable + \ . (empty(l:options) ? '' : ' ' . l:options) + \ . l:args \} endfunction + +function! ale#fixers#ormolu#Fix(buffer) abort + return ale#semver#RunWithVersionCheck( + \ a:buffer, + \ ale#fixers#ormolu#GetExecutable(a:buffer), + \ '%e --version', + \ function('ale#fixers#ormolu#ApplyFixForVersion'), + \) +endfunction diff --git a/test/fixers/test_ormolu_fixer_callback.vader b/test/fixers/test_ormolu_fixer_callback.vader index 8df3fca9d8..3b1848434f 100644 --- a/test/fixers/test_ormolu_fixer_callback.vader +++ b/test/fixers/test_ormolu_fixer_callback.vader @@ -9,16 +9,20 @@ Execute(The ormolu callback should return the correct default values): AssertEqual \ { \ 'command': ale#Escape('ormolu') + \ . ' --stdin-input-file ' + \ . ale#Escape(@%) \ }, \ ale#fixers#ormolu#Fix(bufnr('')) Execute(The ormolu executable and options should be configurable): - let g:ale_nix_nixpkgsfmt_executable = '/path/to/ormolu' - let g:ale_nix_nixpkgsfmt_options = '-h' + let g:ale_haskell_ormolu_executable = '/path/to/ormolu' + let g:ale_haskell_ormolu_options = '-h' AssertEqual \ { \ 'command': ale#Escape('/path/to/ormolu') - \ . ' -h', + \ . ' -h' + \ . ' --stdin-input-file ' + \ . ale#Escape(@%) \ }, - \ ale#fixers#nixpkgsfmt#Fix(bufnr('')) + \ ale#fixers#ormolu#Fix(bufnr(''))