Merge pull request #1856 from sbl/ocamlformat

add ocamlformat support
This commit is contained in:
w0rp 2018-08-28 23:28:30 +01:00 committed by GitHub
commit 79f02fce69
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 83 additions and 2 deletions

View file

@ -151,7 +151,7 @@ formatting.
| nroff | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good)| | nroff | [alex](https://github.com/wooorm/alex) !!, [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good)|
| Objective-C | [clang](http://clang.llvm.org/), [clangd](https://clang.llvm.org/extra/clangd.html) | | Objective-C | [clang](http://clang.llvm.org/), [clangd](https://clang.llvm.org/extra/clangd.html) |
| Objective-C++ | [clang](http://clang.llvm.org/), [clangd](https://clang.llvm.org/extra/clangd.html) | | Objective-C++ | [clang](http://clang.llvm.org/), [clangd](https://clang.llvm.org/extra/clangd.html) |
| OCaml | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-ocaml-merlin` for configuration instructions, [ols](https://github.com/freebroccolo/ocaml-language-server) | | OCaml | [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-ocaml-merlin` for configuration instructions, [ols](https://github.com/freebroccolo/ocaml-language-server), [ocamlformat](https://github.com/ocaml-ppx/ocamlformat) |
| Perl | [perl -c](https://perl.org/), [perl-critic](https://metacpan.org/pod/Perl::Critic), [perltidy](https://metacpan.org/pod/distribution/Perl-Tidy/bin/perltidy) | | Perl | [perl -c](https://perl.org/), [perl-critic](https://metacpan.org/pod/Perl::Critic), [perltidy](https://metacpan.org/pod/distribution/Perl-Tidy/bin/perltidy) |
| PHP | [langserver](https://github.com/felixfbecker/php-language-server), [phan](https://github.com/phan/phan) see `:help ale-php-phan` to instructions, [php -l](https://secure.php.net/), [phpcs](https://github.com/squizlabs/PHP_CodeSniffer), [phpmd](https://phpmd.org), [phpstan](https://github.com/phpstan/phpstan), [phpcbf](https://github.com/squizlabs/PHP_CodeSniffer), [php-cs-fixer](http://cs.sensiolabs.org/) | | PHP | [langserver](https://github.com/felixfbecker/php-language-server), [phan](https://github.com/phan/phan) see `:help ale-php-phan` to instructions, [php -l](https://secure.php.net/), [phpcs](https://github.com/squizlabs/PHP_CodeSniffer), [phpmd](https://phpmd.org), [phpstan](https://github.com/phpstan/phpstan), [phpcbf](https://github.com/squizlabs/PHP_CodeSniffer), [php-cs-fixer](http://cs.sensiolabs.org/) |
| PO | [alex](https://github.com/wooorm/alex) !!, [msgfmt](https://www.gnu.org/software/gettext/manual/html_node/msgfmt-Invocation.html), [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) | | PO | [alex](https://github.com/wooorm/alex) !!, [msgfmt](https://www.gnu.org/software/gettext/manual/html_node/msgfmt-Invocation.html), [proselint](http://proselint.com/), [write-good](https://github.com/btford/write-good) |

View file

@ -180,6 +180,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['haskell'], \ 'suggested_filetypes': ['haskell'],
\ 'description': 'Refactor Haskell files with stylish-haskell.', \ 'description': 'Refactor Haskell files with stylish-haskell.',
\ }, \ },
\ 'ocamlformat': {
\ 'function': 'ale#fixers#ocamlformat#Fix',
\ 'suggested_filetypes': ['ocaml'],
\ 'description': 'Fix OCaml files with ocamlformat.',
\ },
\ 'refmt': { \ 'refmt': {
\ 'function': 'ale#fixers#refmt#Fix', \ 'function': 'ale#fixers#refmt#Fix',
\ 'suggested_filetypes': ['reason'], \ 'suggested_filetypes': ['reason'],

View file

@ -0,0 +1,18 @@
" Author: Stephen Lumenta <@sbl>
" Description: Integration of ocamlformat with ALE.
call ale#Set('ocaml_ocamlformat_executable', 'ocamlformat')
call ale#Set('ocaml_ocamlformat_options', '')
function! ale#fixers#ocamlformat#Fix(buffer) abort
let l:executable = ale#Var(a:buffer, 'ocaml_ocamlformat_executable')
let l:options = ale#Var(a:buffer, 'ocaml_ocamlformat_options')
return {
\ 'command': ale#Escape(l:executable)
\ . (empty(l:options) ? '' : ' ' . l:options)
\ . ' --inplace'
\ . ' %t',
\ 'read_temporary_file': 1,
\}
endfunction

View file

@ -33,5 +33,22 @@ g:ale_ocaml_ols_use_global *g:ale_ocaml_ols_use_global*
This variable can be set to `1` to always use the globally installed This variable can be set to `1` to always use the globally installed
executable. See also |ale-integrations-local-executables|. executable. See also |ale-integrations-local-executables|.
===============================================================================
ocamlformat *ale-ocaml-ocamlformat*
g:ale_ocaml_ocamlformat_executable *g:ale_ocaml_ocamlformat_executable*
*b:ale_ocaml_ocamlformat_executable*
Type: |String|
Default: `'ocamlformat'`
This variable can be set to pass the path of the ocamlformat fixer.
g:ale_ocaml_ocamlformat_options *g:ale_ocaml_ocamlformat_options*
*b:ale_ocaml_ocamlformat_options*
Type: |String|
Default: `''`
This variable can be set to pass additional options to the ocamlformat fixer.
=============================================================================== ===============================================================================
vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl: vim:tw=78:ts=2:sts=2:sw=2:ft=help:norl:

View file

@ -180,6 +180,7 @@ CONTENTS *ale-contents*
ocaml.................................|ale-ocaml-options| ocaml.................................|ale-ocaml-options|
merlin..............................|ale-ocaml-merlin| merlin..............................|ale-ocaml-merlin|
ols.................................|ale-ocaml-ols| ols.................................|ale-ocaml-ols|
ocamlformat.........................|ale-ocaml-ocamlformat|
perl..................................|ale-perl-options| perl..................................|ale-perl-options|
perl................................|ale-perl-perl| perl................................|ale-perl-perl|
perlcritic..........................|ale-perl-perlcritic| perlcritic..........................|ale-perl-perlcritic|
@ -408,7 +409,7 @@ Notes:
* nroff: `alex`!!, `proselint`, `write-good` * nroff: `alex`!!, `proselint`, `write-good`
* Objective-C: `clang`, `clangd` * Objective-C: `clang`, `clangd`
* Objective-C++: `clang`, `clangd` * Objective-C++: `clang`, `clangd`
* OCaml: `merlin` (see |ale-ocaml-merlin|), `ols` * OCaml: `merlin` (see |ale-ocaml-merlin|), `ols`, `ocamlformat`
* Perl: `perl -c`, `perl-critic`, `perltidy` * Perl: `perl -c`, `perl-critic`, `perltidy`
* PHP: `langserver`, `phan`, `php -l`, `phpcs`, `phpmd`, `phpstan`, `phpcbf`, `php-cs-fixer` * PHP: `langserver`, `phan`, `php -l`, `phpcs`, `phpmd`, `phpstan`, `phpcbf`, `php-cs-fixer`
* PO: `alex`!!, `msgfmt`, `proselint`, `write-good` * PO: `alex`!!, `msgfmt`, `proselint`, `write-good`

View file

@ -0,0 +1,40 @@
Before:
Save g:ale_ocaml_ocamlformat_executable
Save g:ale_ocaml_ocamlformat_options
" Use an invalid global executable, so we don't match it.
let g:ale_ocaml_ocamlformat_executable = 'xxxinvalid'
let g:ale_ocaml_ocamlformat_options = ''
call ale#test#SetDirectory('/testplugin/test/fixers')
After:
Restore
call ale#test#RestoreDirectory()
Execute(The ocamlformat callback should return the correct default values):
call ale#test#SetFilename('../ocaml-test-files/testfile.re')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('xxxinvalid')
\ . ' --inplace'
\ . ' %t',
\ },
\ ale#fixers#ocamlformat#Fix(bufnr(''))
Execute(The ocamlformat callback should include custom ocamlformat options):
let g:ale_ocaml_ocamlformat_options = "-m 78"
call ale#test#SetFilename('../ocaml-test-files/testfile.re')
AssertEqual
\ {
\ 'read_temporary_file': 1,
\ 'command': ale#Escape('xxxinvalid')
\ . ' ' . g:ale_ocaml_ocamlformat_options
\ . ' --inplace'
\ . ' %t',
\ },
\ ale#fixers#ocamlformat#Fix(bufnr(''))

View file