@@ -21,7 +21,7 @@ let s:cmdAvailable = {}
21
21
function ! codefmt#mixformat#GetFormatter () abort
22
22
let l: formatter = {
23
23
\ ' name' : ' mixformat' ,
24
- \ ' setup_instructions' : ' mix is usually installed with Elixir' .
24
+ \ ' setup_instructions' : ' mix is usually installed with Elixir ' .
25
25
\ ' (https://elixir-lang.org/install.html). ' .
26
26
\ " If mix is not in your path, configure it in .vimrc:\n " .
27
27
\ ' Glaive codefmt mix_executable=/path/to/mix' }
@@ -40,17 +40,20 @@ function! codefmt#mixformat#GetFormatter() abort
40
40
endfunction
41
41
42
42
" "
43
- " Reformat the current buffer using ktfmt , only targeting {ranges}.
43
+ " Reformat the current buffer using mix format , only targeting {ranges}.
44
44
function l: formatter .FormatRange (startline, endline) abort
45
45
let l: filename = expand (' %:p' )
46
46
if empty (l: filename )
47
+ let l: dir = getcwd ()
48
+ " Default filename per https://hexdocs.pm/mix/Mix.Tasks.Format.html
47
49
let l: filename = ' stdin.exs'
50
+ else
51
+ let l: dir = s: findMixDir (l: filename )
48
52
endif
49
53
" mix format docs: https://hexdocs.pm/mix/main/Mix.Tasks.Format.html
50
54
let l: cmd = codefmt#formatterhelpers#ResolveFlagToArray (' mix_executable' )
51
55
" Specify stdin as the file
52
56
let l: cmd = l: cmd + [' format' , ' --stdin-filename=' . l: filename , ' -' ]
53
- let l: dir = l: filename == ' stdin.exs' ? getcwd () : s: findMixDir (l: filename )
54
57
let l: syscall = maktaba#syscall#Create (l: cmd ).WithCwd (l: dir )
55
58
try
56
59
" mix format doesn't have a line-range option, but does a reasonable job
0 commit comments