Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fixer for OCaml ocp-indent #2436

Merged
merged 5 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions autoload/ale/fix/registry.vim
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,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) ? '': ' ' . ale#Escape(l:options))
mkanenobu marked this conversation as resolved.
Show resolved Hide resolved
\}
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 @@ -292,6 +292,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 @@ -2049,6 +2049,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 @@ -301,6 +301,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(''))