Add support for Dune (#4263)

* Add support for dune

* Add test

* Undo reformatting of Markdown file

* Refer to ale-ocaml-dune from ale.txt
This commit is contained in:
Albert Peschar 2022-07-26 11:55:22 +03:00 committed by GitHub
parent 0ea53870b6
commit 854d606333
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 80 additions and 0 deletions

View File

@ -78,6 +78,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['dhall'], \ 'suggested_filetypes': ['dhall'],
\ 'description': 'Standard code formatter for the Dhall language and removing dead code', \ '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': { \ 'fecs': {
\ 'function': 'ale#fixers#fecs#Fix', \ 'function': 'ale#fixers#fecs#Fix',
\ 'suggested_filetypes': ['javascript', 'css', 'html'], \ 'suggested_filetypes': ['javascript', 'css', 'html'],

View File

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

View File

@ -2,6 +2,26 @@
ALE OCaml Integration *ale-ocaml-options* 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* merlin *ale-ocaml-merlin*

View File

@ -386,6 +386,7 @@ Notes:
* `clangd` * `clangd`
* `uncrustify` * `uncrustify`
* OCaml * OCaml
* `dune`
* `merlin` (see |ale-ocaml-merlin|) * `merlin` (see |ale-ocaml-merlin|)
* `ocamlformat` * `ocamlformat`
* `ocamllsp` * `ocamllsp`

View File

@ -3041,6 +3041,7 @@ documented in additional help files.
clangd................................|ale-objcpp-clangd| clangd................................|ale-objcpp-clangd|
uncrustify............................|ale-objcpp-uncrustify| uncrustify............................|ale-objcpp-uncrustify|
ocaml...................................|ale-ocaml-options| ocaml...................................|ale-ocaml-options|
dune..................................|ale-ocaml-dune|
merlin................................|ale-ocaml-merlin| merlin................................|ale-ocaml-merlin|
ocamllsp..............................|ale-ocaml-ocamllsp| ocamllsp..............................|ale-ocaml-ocamllsp|
ols...................................|ale-ocaml-ols| ols...................................|ale-ocaml-ols|

View File

@ -395,6 +395,7 @@ formatting.
* [clangd](https://clang.llvm.org/extra/clangd.html) * [clangd](https://clang.llvm.org/extra/clangd.html)
* [uncrustify](https://github.com/uncrustify/uncrustify) * [uncrustify](https://github.com/uncrustify/uncrustify)
* OCaml * OCaml
* [dune](https://dune.build/)
* [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-ocaml-merlin` for configuration instructions * [merlin](https://github.com/the-lambda-church/merlin) see `:help ale-ocaml-merlin` for configuration instructions
* [ocamlformat](https://github.com/ocaml-ppx/ocamlformat) * [ocamlformat](https://github.com/ocaml-ppx/ocamlformat)
* [ocamllsp](https://github.com/ocaml/ocaml-lsp) * [ocamllsp](https://github.com/ocaml/ocaml-lsp)

View File

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