Skip to content

Commit

Permalink
Add fixer for OCaml ocp-indent (#2436)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkanenobu authored and w0rp committed May 7, 2019
1 parent 548ee56 commit c10da0e
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 0 deletions.
5 changes: 5 additions & 0 deletions autoload/ale/fix/registry.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
18 changes: 18 additions & 0 deletions autoload/ale/fixers/ocp_indent.vim
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions doc/ale-ocaml.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
1 change: 1 addition & 0 deletions doc/ale-supported-languages-and-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ Notes:
* OCaml
* `merlin` (see |ale-ocaml-merlin|)
* `ocamlformat`
* `ocp-indent`
* `ols`
* Pawn
* `uncrustify`
Expand Down
1 change: 1 addition & 0 deletions doc/ale.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
1 change: 1 addition & 0 deletions supported-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions test/fixers/test_ocp_indent_fixer_callback.vader
Original file line number Diff line number Diff line change
@@ -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(''))

0 comments on commit c10da0e

Please sign in to comment.