Make ocamlformat work without temporary files
Problem: ocamlformat is configured to format files in-place and thus go via creating a temporary file for that. Because temporary file resides in a different directory ocamlformat can't find `.ocamlformat` configuration files in an original location of source files. Solution: ocamlformat since version 0.8 can read sources on stdin and spur result on stdout. We reconfigure ocamlformat to use a simpler interface.
This commit is contained in:
parent
acdc99b94d
commit
b9fb62a4cd
@ -5,14 +5,14 @@ call ale#Set('ocaml_ocamlformat_executable', 'ocamlformat')
|
|||||||
call ale#Set('ocaml_ocamlformat_options', '')
|
call ale#Set('ocaml_ocamlformat_options', '')
|
||||||
|
|
||||||
function! ale#fixers#ocamlformat#Fix(buffer) abort
|
function! ale#fixers#ocamlformat#Fix(buffer) abort
|
||||||
|
let l:filename = expand('#' . a:buffer . ':p')
|
||||||
let l:executable = ale#Var(a:buffer, 'ocaml_ocamlformat_executable')
|
let l:executable = ale#Var(a:buffer, 'ocaml_ocamlformat_executable')
|
||||||
let l:options = ale#Var(a:buffer, 'ocaml_ocamlformat_options')
|
let l:options = ale#Var(a:buffer, 'ocaml_ocamlformat_options')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
\ 'command': ale#Escape(l:executable)
|
\ 'command': ale#Escape(l:executable)
|
||||||
\ . (empty(l:options) ? '' : ' ' . l:options)
|
\ . (empty(l:options) ? '' : ' ' . l:options)
|
||||||
\ . ' --inplace'
|
\ . ' --name=' . ale#Escape(l:filename)
|
||||||
\ . ' %t',
|
\ . ' -'
|
||||||
\ 'read_temporary_file': 1,
|
|
||||||
\}
|
\}
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -18,10 +18,9 @@ Execute(The ocamlformat callback should return the correct default values):
|
|||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {
|
\ {
|
||||||
\ 'read_temporary_file': 1,
|
|
||||||
\ 'command': ale#Escape('xxxinvalid')
|
\ 'command': ale#Escape('xxxinvalid')
|
||||||
\ . ' --inplace'
|
\ . ' --name=' . ale#Escape(bufname(bufnr('')))
|
||||||
\ . ' %t',
|
\ . ' -',
|
||||||
\ },
|
\ },
|
||||||
\ ale#fixers#ocamlformat#Fix(bufnr(''))
|
\ ale#fixers#ocamlformat#Fix(bufnr(''))
|
||||||
|
|
||||||
@ -31,10 +30,9 @@ Execute(The ocamlformat callback should include custom ocamlformat options):
|
|||||||
|
|
||||||
AssertEqual
|
AssertEqual
|
||||||
\ {
|
\ {
|
||||||
\ 'read_temporary_file': 1,
|
|
||||||
\ 'command': ale#Escape('xxxinvalid')
|
\ 'command': ale#Escape('xxxinvalid')
|
||||||
\ . ' ' . g:ale_ocaml_ocamlformat_options
|
\ . ' ' . g:ale_ocaml_ocamlformat_options
|
||||||
\ . ' --inplace'
|
\ . ' --name=' . ale#Escape(bufname(bufnr('')))
|
||||||
\ . ' %t',
|
\ . ' -',
|
||||||
\ },
|
\ },
|
||||||
\ ale#fixers#ocamlformat#Fix(bufnr(''))
|
\ ale#fixers#ocamlformat#Fix(bufnr(''))
|
||||||
|
Loading…
Reference in New Issue
Block a user