From 8adee9cb0b99cda81b3b2f15112a7618659e3f5c Mon Sep 17 00:00:00 2001 From: Eric Ahlberg Date: Mon, 20 Nov 2023 11:16:08 +0100 Subject: [PATCH 1/6] Fix ormolu - Enable --stdin-input-file . option by default - Use same pattern as other Haskell fixers --- autoload/ale/fixers/ormolu.vim | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/autoload/ale/fixers/ormolu.vim b/autoload/ale/fixers/ormolu.vim index 69b55c1f12..cfa987d292 100644 --- a/autoload/ale/fixers/ormolu.vim +++ b/autoload/ale/fixers/ormolu.vim @@ -1,12 +1,20 @@ 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#Fix(buffer) abort + let l:executable = ale#fixers#ormolu#GetExecutable(a:buffer) let l:options = ale#Var(a:buffer, 'haskell_ormolu_options') return { - \ 'command': ale#Escape(l:executable) - \ . (empty(l:options) ? '' : ' ' . l:options), + \ 'command': l:executable + \ . (empty(l:options) ? '' : ' ' . l:options) + \ . ' --stdin-input-file ' + \ . ale#Escape(@%), \} endfunction From 08489137b1307b987ee535693850ddcc53ef2fc1 Mon Sep 17 00:00:00 2001 From: Eric Ahlberg Date: Mon, 20 Nov 2023 11:21:29 +0100 Subject: [PATCH 2/6] Fix typo in test --- test/fixers/test_ormolu_fixer_callback.vader | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/fixers/test_ormolu_fixer_callback.vader b/test/fixers/test_ormolu_fixer_callback.vader index 8df3fca9d8..3e6af199f0 100644 --- a/test/fixers/test_ormolu_fixer_callback.vader +++ b/test/fixers/test_ormolu_fixer_callback.vader @@ -13,12 +13,12 @@ Execute(The ormolu callback should return the correct default values): \ 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', \ }, - \ ale#fixers#nixpkgsfmt#Fix(bufnr('')) + \ ale#fixers#ormolu#Fix(bufnr('')) From e628299769e9cb71bacf2f151c7e99c706644a88 Mon Sep 17 00:00:00 2001 From: Eric Ahlberg Date: Mon, 20 Nov 2023 11:21:39 +0100 Subject: [PATCH 3/6] Update test --- test/fixers/test_ormolu_fixer_callback.vader | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/fixers/test_ormolu_fixer_callback.vader b/test/fixers/test_ormolu_fixer_callback.vader index 3e6af199f0..3b1848434f 100644 --- a/test/fixers/test_ormolu_fixer_callback.vader +++ b/test/fixers/test_ormolu_fixer_callback.vader @@ -9,6 +9,8 @@ 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('')) @@ -19,6 +21,8 @@ Execute(The ormolu executable and options should be configurable): AssertEqual \ { \ 'command': ale#Escape('/path/to/ormolu') - \ . ' -h', + \ . ' -h' + \ . ' --stdin-input-file ' + \ . ale#Escape(@%) \ }, \ ale#fixers#ormolu#Fix(bufnr('')) From d97b8363670664ecde0786cbfa057dd928e895d1 Mon Sep 17 00:00:00 2001 From: Eric Ahlberg Date: Wed, 10 Jan 2024 14:11:25 +0100 Subject: [PATCH 4/6] Address feedback --- autoload/ale/fixers/ormolu.vim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/autoload/ale/fixers/ormolu.vim b/autoload/ale/fixers/ormolu.vim index cfa987d292..941271ccb0 100644 --- a/autoload/ale/fixers/ormolu.vim +++ b/autoload/ale/fixers/ormolu.vim @@ -11,10 +11,15 @@ function! ale#fixers#ormolu#Fix(buffer) 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, 3, 0]) + let l:args = ' --stdin-input-file %s' + else + let l:args = ' %s' + endif + return { \ 'command': l:executable \ . (empty(l:options) ? '' : ' ' . l:options) - \ . ' --stdin-input-file ' - \ . ale#Escape(@%), + \ . l:args \} endfunction From 4f5e0cf82111e8ad73cb11e043c0828a490b06f5 Mon Sep 17 00:00:00 2001 From: Eric Ahlberg Date: Wed, 10 Jan 2024 16:33:25 +0100 Subject: [PATCH 5/6] WIP --- autoload/ale/fixers/ormolu.vim | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/autoload/ale/fixers/ormolu.vim b/autoload/ale/fixers/ormolu.vim index 941271ccb0..65bb0abbce 100644 --- a/autoload/ale/fixers/ormolu.vim +++ b/autoload/ale/fixers/ormolu.vim @@ -7,7 +7,7 @@ function! ale#fixers#ormolu#GetExecutable(buffer) abort return ale#handlers#haskell_stack#EscapeExecutable(l:executable, 'ormolu') endfunction -function! ale#fixers#ormolu#Fix(buffer) abort +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') @@ -23,3 +23,12 @@ function! ale#fixers#ormolu#Fix(buffer) abort \ . 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 From a2dbb0c8b35b10cadf0a9af6bb2784e74928dc35 Mon Sep 17 00:00:00 2001 From: Eric Ahlberg Date: Wed, 10 Jan 2024 16:44:53 +0100 Subject: [PATCH 6/6] WIP --- autoload/ale/fixers/ormolu.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/ale/fixers/ormolu.vim b/autoload/ale/fixers/ormolu.vim index 65bb0abbce..993de4f873 100644 --- a/autoload/ale/fixers/ormolu.vim +++ b/autoload/ale/fixers/ormolu.vim @@ -11,7 +11,7 @@ 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, 3, 0]) + if ale#semver#GTE(a:version, [0, 8, 0]) let l:args = ' --stdin-input-file %s' else let l:args = ' %s'