summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <w0rp@users.noreply.github.com>2018-08-28 23:28:30 +0100
committerGitHub <noreply@github.com>2018-08-28 23:28:30 +0100
commit79f02fce69a0dceb8bbbe2c6f5a7cebceaa34be6 (patch)
treec0ce904f116a04b0b24793d5b129bc3ee6ba6e7d
parentd4ce201cc298cc9b0556111fef39f6ffa7b3fd59 (diff)
parentb7169c33e78d707761e5ff1320fa7696fbec4bbd (diff)
downloadale-79f02fce69a0dceb8bbbe2c6f5a7cebceaa34be6.zip
Merge pull request #1856 from sbl/ocamlformat
add ocamlformat support
-rw-r--r--README.md2
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/ocamlformat.vim18
-rw-r--r--doc/ale-ocaml.txt17
-rw-r--r--doc/ale.txt3
-rw-r--r--test/fixers/test_ocamlformat_fixer_callback.vader40
-rw-r--r--test/ocaml-test-files/testfile.ml0
7 files changed, 83 insertions, 2 deletions
diff --git a/README.md b/README.md
index b7d9dd9c..e8108733 100644
--- a/README.md
+++ b/README.md
@@ -151,7 +151,7 @@ formatting.
| 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) |
-| 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) |
| 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) |
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index dfcdc98f..ead4e058 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -180,6 +180,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['haskell'],
\ 'description': 'Refactor Haskell files with stylish-haskell.',
\ },
+\ 'ocamlformat': {
+\ 'function': 'ale#fixers#ocamlformat#Fix',
+\ 'suggested_filetypes': ['ocaml'],
+\ 'description': 'Fix OCaml files with ocamlformat.',
+\ },
\ 'refmt': {
\ 'function': 'ale#fixers#refmt#Fix',
\ 'suggested_filetypes': ['reason'],
diff --git a/autoload/ale/fixers/ocamlformat.vim b/autoload/ale/fixers/ocamlformat.vim
new file mode 100644
index 00000000..fac142aa
--- /dev/null
+++ b/autoload/ale/fixers/ocamlformat.vim
@@ -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
diff --git a/doc/ale-ocaml.txt b/doc/ale-ocaml.txt
index a7ef8d29..adf17716 100644
--- a/doc/ale-ocaml.txt
+++ b/doc/ale-ocaml.txt
@@ -34,4 +34,21 @@ g:ale_ocaml_ols_use_global *g:ale_ocaml_ols_use_global*
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:
diff --git a/doc/ale.txt b/doc/ale.txt
index 80d8b96c..29f74e1a 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -180,6 +180,7 @@ CONTENTS *ale-contents*
ocaml.................................|ale-ocaml-options|
merlin..............................|ale-ocaml-merlin|
ols.................................|ale-ocaml-ols|
+ ocamlformat.........................|ale-ocaml-ocamlformat|
perl..................................|ale-perl-options|
perl................................|ale-perl-perl|
perlcritic..........................|ale-perl-perlcritic|
@@ -408,7 +409,7 @@ Notes:
* nroff: `alex`!!, `proselint`, `write-good`
* 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`
* PHP: `langserver`, `phan`, `php -l`, `phpcs`, `phpmd`, `phpstan`, `phpcbf`, `php-cs-fixer`
* PO: `alex`!!, `msgfmt`, `proselint`, `write-good`
diff --git a/test/fixers/test_ocamlformat_fixer_callback.vader b/test/fixers/test_ocamlformat_fixer_callback.vader
new file mode 100644
index 00000000..d2aee066
--- /dev/null
+++ b/test/fixers/test_ocamlformat_fixer_callback.vader
@@ -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(''))
diff --git a/test/ocaml-test-files/testfile.ml b/test/ocaml-test-files/testfile.ml
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/ocaml-test-files/testfile.ml