diff options
-rw-r--r-- | autoload/ale/fix/registry.vim | 5 | ||||
-rw-r--r-- | autoload/ale/fixers/fourmolu.vim | 20 | ||||
-rw-r--r-- | doc/ale-haskell.txt | 20 | ||||
-rw-r--r-- | doc/ale-supported-languages-and-tools.txt | 1 | ||||
-rw-r--r-- | doc/ale.txt | 1 | ||||
-rw-r--r-- | supported-tools.md | 1 | ||||
-rw-r--r-- | test/fixers/test_fourmolu_fixer_callback.vader | 29 |
7 files changed, 77 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index f7fff6a7..66cdc707 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -561,6 +561,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['haskell'], \ 'description': 'A formatter for Haskell source code.', \ }, +\ 'fourmolu': { +\ 'function': 'ale#fixers#fourmolu#Fix', +\ 'suggested_filetypes': ['haskell'], +\ 'description': 'A formatter for Haskell source code.', +\ }, \ 'jsonnetfmt': { \ 'function': 'ale#fixers#jsonnetfmt#Fix', \ 'suggested_filetypes': ['jsonnet'], diff --git a/autoload/ale/fixers/fourmolu.vim b/autoload/ale/fixers/fourmolu.vim new file mode 100644 index 00000000..399ec0f4 --- /dev/null +++ b/autoload/ale/fixers/fourmolu.vim @@ -0,0 +1,20 @@ +call ale#Set('haskell_fourmolu_executable', 'fourmolu') +call ale#Set('haskell_fourmolu_options', '') + +function! ale#fixers#fourmolu#GetExecutable(buffer) abort + let l:executable = ale#Var(a:buffer, 'haskell_fourmolu_executable') + + return ale#handlers#haskell_stack#EscapeExecutable(l:executable, 'fourmolu') +endfunction + +function! ale#fixers#fourmolu#Fix(buffer) abort + let l:executable = ale#fixers#fourmolu#GetExecutable(a:buffer) + let l:options = ale#Var(a:buffer, 'haskell_fourmolu_options') + + return { + \ 'command': l:executable + \ . (empty(l:options) ? '' : ' ' . l:options) + \ . ' --stdin-input-file ' + \ . ale#Escape(@%), + \} +endfunction diff --git a/doc/ale-haskell.txt b/doc/ale-haskell.txt index bd5a5edf..bcd15724 100644 --- a/doc/ale-haskell.txt +++ b/doc/ale-haskell.txt @@ -225,4 +225,24 @@ g:ale_haskell_ormolu_options *g:ale_haskell_ormolu_options* =============================================================================== +fourmolu *ale-haskell-fourmolu* + +g:ale_haskell_fourmolu_executable *g:ale_haskell_fourmolu_executable* + *b:ale_haskell_fourmolu_executable* + Type: |String| + Default: `'fourmolu'` + + This variable can be changed to use a different executable for fourmolu. + + +g:ale_haskell_fourmolu_options *g:ale_haskell_fourmolu_options* + *b:ale_haskell_fourmolu_options* + Type: |String| + Default: `''` + + This variable can be used to pass extra options to the underlying fourmolu + executable. + + +=============================================================================== vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index d56d0a76..6369224a 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -236,6 +236,7 @@ Notes: * `cabal-ghc` * `cspell` * `floskell` + * `fourmolu` * `ghc` * `ghc-mod` * `hdevtools` diff --git a/doc/ale.txt b/doc/ale.txt index ffdde04c..76f00c43 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -3019,6 +3019,7 @@ documented in additional help files. stylish-haskell.......................|ale-haskell-stylish-haskell| hie...................................|ale-haskell-hie| ormolu................................|ale-haskell-ormolu| + fourmolu..............................|ale-haskell-fourmolu| hcl.....................................|ale-hcl-options| packer-fmt............................|ale-hcl-packer-fmt| terraform-fmt.........................|ale-hcl-terraform-fmt| diff --git a/supported-tools.md b/supported-tools.md index 0767cc35..a69e8a76 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -245,6 +245,7 @@ formatting. * [cabal-ghc](https://www.haskell.org/cabal/) * [cspell](https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell) * [floskell](https://github.com/ennocramer/floskell) + * [fourmolu](https://github.com/fourmolu/fourmolu) * [ghc](https://www.haskell.org/ghc/) * [ghc-mod](https://github.com/DanielG/ghc-mod) * [hdevtools](https://hackage.haskell.org/package/hdevtools) diff --git a/test/fixers/test_fourmolu_fixer_callback.vader b/test/fixers/test_fourmolu_fixer_callback.vader new file mode 100644 index 00000000..728c02ed --- /dev/null +++ b/test/fixers/test_fourmolu_fixer_callback.vader @@ -0,0 +1,29 @@ +Before: + Save g:ale_haskell_fourmolu_executable + Save g:ale_haskell_fourmolu_options + +After: + Restore + +Execute(The fourmolu callback should return the correct default values): + AssertEqual + \ { + \ 'command': ale#Escape('fourmolu') + \ . ' --stdin-input-file ' + \ . ale#Escape(@%) + \ }, + \ ale#fixers#fourmolu#Fix(bufnr('')) + +Execute(The fourmolu executable and options should be configurable): + let g:ale_haskell_fourmolu_executable = '/path/to/fourmolu' + let g:ale_haskell_fourmolu_options = '-h' + + AssertEqual + \ { + \ 'command': ale#Escape('/path/to/fourmolu') + \ . ' -h' + \ . ' --stdin-input-file ' + \ . ale#Escape(@%) + \ }, + \ ale#fixers#fourmolu#Fix(bufnr('')) + |