mirror of https://github.com/dense-analysis/ale
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:
parent
0ea53870b6
commit
854d606333
|
@ -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'],
|
||||
|
|
|
@ -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
|
|
@ -2,6 +2,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*
|
||||
|
||||
|
|
|
@ -386,6 +386,7 @@ Notes:
|
|||
* `clangd`
|
||||
* `uncrustify`
|
||||
* OCaml
|
||||
* `dune`
|
||||
* `merlin` (see |ale-ocaml-merlin|)
|
||||
* `ocamlformat`
|
||||
* `ocamllsp`
|
||||
|
|
|
@ -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|
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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(''))
|
Loading…
Reference in New Issue