diff options
-rw-r--r-- | autoload/ale/fix/registry.vim | 5 | ||||
-rw-r--r-- | autoload/ale/fixers/ocp_indent.vim | 18 | ||||
-rw-r--r-- | doc/ale-ocaml.txt | 28 | ||||
-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_ocp_indent_fixer_callback.vader | 34 |
7 files changed, 88 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index 4802ee1b..3a36f367 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -220,6 +220,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['ocaml'], \ 'description': 'Fix OCaml files with ocamlformat.', \ }, +\ 'ocp-indent': { +\ 'function': 'ale#fixers#ocp_indent#Fix', +\ 'suggested_filetypes': ['ocaml'], +\ 'description': 'Fix OCaml files with ocp-indent.', +\ }, \ 'refmt': { \ 'function': 'ale#fixers#refmt#Fix', \ 'suggested_filetypes': ['reason'], diff --git a/autoload/ale/fixers/ocp_indent.vim b/autoload/ale/fixers/ocp_indent.vim new file mode 100644 index 00000000..e1b047b3 --- /dev/null +++ b/autoload/ale/fixers/ocp_indent.vim @@ -0,0 +1,18 @@ +" Author: Kanenobu Mitsuru +" Description: Integration of ocp-indent with ALE. + +call ale#Set('ocaml_ocp_indent_executable', 'ocp-indent') +call ale#Set('ocaml_ocp_indent_options', '') +call ale#Set('ocaml_ocp_indent_config', '') + +function! ale#fixers#ocp_indent#Fix(buffer) abort + let l:executable = ale#Var(a:buffer, 'ocaml_ocp_indent_executable') + let l:config = ale#Var(a:buffer, 'ocaml_ocp_indent_config') + let l:options = ale#Var(a:buffer, 'ocaml_ocp_indent_options') + + return { + \ 'command': ale#Escape(l:executable) + \ . (empty(l:config) ? '' : ' --config=' . ale#Escape(l:config)) + \ . (empty(l:options) ? '': ' ' . l:options) + \} +endfunction diff --git a/doc/ale-ocaml.txt b/doc/ale-ocaml.txt index adf17716..8b644c17 100644 --- a/doc/ale-ocaml.txt +++ b/doc/ale-ocaml.txt @@ -51,4 +51,32 @@ g:ale_ocaml_ocamlformat_options *g:ale_ocaml_ocamlformat_options* This variable can be set to pass additional options to the ocamlformat fixer. =============================================================================== +ocp-indent *ale-ocaml-ocp-indent* + +g:ale_ocaml_ocp_indent_executable *g:ale_ocaml_ocp_indent_executable* + *b:ale_ocaml_ocp_indent_executable* + Type: |String| + Default: `ocp-indent` + + This variable can be set to pass the path of the ocp-indent. + +g:ale_ocaml_ocp_indent_options *g:ale_ocaml_ocp_indent_options* + *b:ale_ocaml_ocp_indent_options* + Type: |String| + Default: `''` + + This variable can be set to pass additional options to the ocp-indent. + +g:ale_ocaml_ocp_indent_config *g:ale_ocaml_ocp_indent_config* + *b:ale_ocaml_ocp_indent_config* + Type: |String| + Default: `''` + + This variable can be set to pass additional config to the ocp-indent. + Expand after "--config=". + + "ocp-indent" can also be enabled from ocamlformat config. + + +=============================================================================== 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 607c65c2..d6fbafa6 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -293,6 +293,7 @@ Notes: * OCaml * `merlin` (see |ale-ocaml-merlin|) * `ocamlformat` + * `ocp-indent` * `ols` * Pawn * `uncrustify` diff --git a/doc/ale.txt b/doc/ale.txt index 755064c1..b777e575 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -2105,6 +2105,7 @@ documented in additional help files. merlin................................|ale-ocaml-merlin| ols...................................|ale-ocaml-ols| ocamlformat...........................|ale-ocaml-ocamlformat| + ocp-indent............................|ale-ocaml-ocp-indent| pawn....................................|ale-pawn-options| uncrustify............................|ale-pawn-uncrustify| perl....................................|ale-perl-options| diff --git a/supported-tools.md b/supported-tools.md index 1c02e77c..18d69388 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -302,6 +302,7 @@ formatting. * OCaml * [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-ocaml-merlin` for configuration instructions * [ocamlformat](https://github.com/ocaml-ppx/ocamlformat) + * [ocp-indent](https://github.com/OCamlPro/ocp-indent) * [ols](https://github.com/freebroccolo/ocaml-language-server) * Pawn * [uncrustify](https://github.com/uncrustify/uncrustify) diff --git a/test/fixers/test_ocp_indent_fixer_callback.vader b/test/fixers/test_ocp_indent_fixer_callback.vader new file mode 100644 index 00000000..1f61f383 --- /dev/null +++ b/test/fixers/test_ocp_indent_fixer_callback.vader @@ -0,0 +1,34 @@ +Before: + Save g:ale_ocaml_ocp_indent_executable + Save g:ale_ocaml_ocpindent_options + + " Use an invalid global executable + let g:ale_ocaml_ocp_indent_executable = 'xxxinvalid' + let g:ale_ocaml_ocp_indent_options = '' + + call ale#test#SetDirectory('/testplugin/test/fixers') + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(The ocp_indent callback should return the correct default values): + call ale#test#SetFilename('../ocaml-test-files/ocp_inden_testfile.re') + + AssertEqual + \ { + \ 'command': ale#Escape('xxxinvalid') + \ }, + \ ale#fixers#ocp_indent#Fix(bufnr('')) + +Execute(The ocp_indent callback should include custom ocp_indent options): + let g:ale_ocaml_ocp_indent_config = "base=4, type=4" + call ale#test#SetFilename('../ocaml-test-files/ocp_inden_testfile.re') + + AssertEqual + \ { + \ 'command': ale#Escape('xxxinvalid') + \ . ' --config=' . ale#Escape(g:ale_ocaml_ocp_indent_config) + \ }, + \ ale#fixers#ocp_indent#Fix(bufnr('')) |