diff options
author | Albert Peschar <albert@peschar.net> | 2022-07-26 11:55:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-26 17:55:22 +0900 |
commit | 854d6063331c686ded959ecb17830fb8c34f2db3 (patch) | |
tree | e2c871616021f38761e5f0c9c1bac4158acdb0b0 | |
parent | 0ea53870b6b93eb3b20dbd8317291cfe06dc38bd (diff) | |
download | ale-854d6063331c686ded959ecb17830fb8c34f2db3.zip |
Add support for Dune (#4263)
* Add support for dune
* Add test
* Undo reformatting of Markdown file
* Refer to ale-ocaml-dune from ale.txt
-rw-r--r-- | autoload/ale/fix/registry.vim | 5 | ||||
-rw-r--r-- | autoload/ale/fixers/dune.vim | 16 | ||||
-rw-r--r-- | doc/ale-ocaml.txt | 20 | ||||
-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_dune_fixer_callback.vader | 36 |
7 files changed, 80 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim index e9b289c6..85fef81d 100644 --- a/autoload/ale/fix/registry.vim +++ b/autoload/ale/fix/registry.vim @@ -78,6 +78,11 @@ let s:default_registry = { \ 'suggested_filetypes': ['dhall'], \ 'description': 'Standard code formatter for the Dhall language and removing dead code', \ }, +\ 'dune': { +\ 'function': 'ale#fixers#dune#Fix', +\ 'suggested_filetypes': ['dune'], +\ 'description': 'Fix dune files with dune format', +\ }, \ 'fecs': { \ 'function': 'ale#fixers#fecs#Fix', \ 'suggested_filetypes': ['javascript', 'css', 'html'], diff --git a/autoload/ale/fixers/dune.vim b/autoload/ale/fixers/dune.vim new file mode 100644 index 00000000..6ef7ec9f --- /dev/null +++ b/autoload/ale/fixers/dune.vim @@ -0,0 +1,16 @@ +" Author: Albert Peschar <albert@peschar.net> +" Description: Fix files with dune format. + +call ale#Set('ocaml_dune_executable', 'dune') +call ale#Set('ocaml_dune_options', '') + +function! ale#fixers#dune#Fix(buffer) abort + let l:executable = ale#Var(a:buffer, 'ocaml_dune_executable') + let l:options = ale#Var(a:buffer, 'ocaml_dune_options') + + return { + \ 'command': ale#Escape(l:executable) + \ . ' format' + \ . (empty(l:options) ? '' : ' ' . l:options), + \} +endfunction diff --git a/doc/ale-ocaml.txt b/doc/ale-ocaml.txt index afbc2386..a361a7b4 100644 --- a/doc/ale-ocaml.txt +++ b/doc/ale-ocaml.txt @@ -3,6 +3,26 @@ ALE OCaml Integration *ale-ocaml-options* =============================================================================== +dune *ale-ocaml-dune* + + Dune is a build system for OCaml projects. The `dune format` command is + supported for automatically formatting `dune` and `dune-project` files. + +g:ale_ocaml_dune_executable *g:ale_ocaml_dune_executable* + *b:ale_ocaml_dune_executable* + Type: |String| + Default: `'dune'` + + This variable can be set to pass the path to dune. + +g:ale_ocaml_dune_options *g:ale_ocaml_dune_options* + *b:ale_ocaml_dune_options* + Type: |String| + Default: `''` + + This variable can be set to pass additional options to the dune fixer. + +=============================================================================== merlin *ale-ocaml-merlin* To use merlin linter for OCaml source code you need to make sure Merlin for diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt index d66b9a02..a0a7fbd5 100644 --- a/doc/ale-supported-languages-and-tools.txt +++ b/doc/ale-supported-languages-and-tools.txt @@ -386,6 +386,7 @@ Notes: * `clangd` * `uncrustify` * OCaml + * `dune` * `merlin` (see |ale-ocaml-merlin|) * `ocamlformat` * `ocamllsp` diff --git a/doc/ale.txt b/doc/ale.txt index cabca300..828d5e2d 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -3041,6 +3041,7 @@ documented in additional help files. clangd................................|ale-objcpp-clangd| uncrustify............................|ale-objcpp-uncrustify| ocaml...................................|ale-ocaml-options| + dune..................................|ale-ocaml-dune| merlin................................|ale-ocaml-merlin| ocamllsp..............................|ale-ocaml-ocamllsp| ols...................................|ale-ocaml-ols| diff --git a/supported-tools.md b/supported-tools.md index 235f211e..7a71c14c 100644 --- a/supported-tools.md +++ b/supported-tools.md @@ -395,6 +395,7 @@ formatting. * [clangd](https://clang.llvm.org/extra/clangd.html) * [uncrustify](https://github.com/uncrustify/uncrustify) * OCaml + * [dune](https://dune.build/) * [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-ocaml-merlin` for configuration instructions * [ocamlformat](https://github.com/ocaml-ppx/ocamlformat) * [ocamllsp](https://github.com/ocaml/ocaml-lsp) diff --git a/test/fixers/test_dune_fixer_callback.vader b/test/fixers/test_dune_fixer_callback.vader new file mode 100644 index 00000000..7fc0733c --- /dev/null +++ b/test/fixers/test_dune_fixer_callback.vader @@ -0,0 +1,36 @@ +Before: + Save g:ale_ocaml_dune_executable + Save g:ale_ocaml_dune_options + + " Use an invalid global executable, so we don't match it. + let g:ale_ocaml_dune_executable = 'xxxinvalid' + let g:ale_ocaml_dune_options = '' + + call ale#test#SetDirectory('/testplugin/test/fixers') + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(The dune callback should return the correct default values): + call ale#test#SetFilename('../test-files/ocaml/testfile.re') + + AssertEqual + \ { + \ 'command': ale#Escape('xxxinvalid') + \ . ' format', + \ }, + \ ale#fixers#dune#Fix(bufnr('')) + +Execute(The dune callback should include custom dune options): + let g:ale_ocaml_dune_options = "--random-option" + call ale#test#SetFilename('../test-files/ocaml/testfile.re') + + AssertEqual + \ { + \ 'command': ale#Escape('xxxinvalid') + \ . ' format' + \ . ' ' . g:ale_ocaml_dune_options, + \ }, + \ ale#fixers#dune#Fix(bufnr('')) |