Add fixer for OCaml ocp-indent (#2436)

This commit is contained in:
Kanenobu Mitsuru 2019-05-08 02:50:26 +09:00 committed by w0rp
parent 548ee56f40
commit c10da0e390
7 changed files with 88 additions and 0 deletions

View File

@ -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'],

View File

@ -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

View File

@ -50,5 +50,33 @@ 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:

View File

@ -293,6 +293,7 @@ Notes:
* OCaml
* `merlin` (see |ale-ocaml-merlin|)
* `ocamlformat`
* `ocp-indent`
* `ols`
* Pawn
* `uncrustify`

View File

@ -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|

View File

@ -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)

View File

@ -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(''))