Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Haskell ormolu fixer #4654

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions autoload/ale/fixers/ormolu.vim
Original file line number Diff line number Diff line change
@@ -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
12 changes: 8 additions & 4 deletions test/fixers/test_ormolu_fixer_callback.vader
Original file line number Diff line number Diff line change
Expand Up @@ -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(''))