Skip to content

Commit e2a0bbf

Browse files
committed
Don't behave differently when editing a file named stdin.exs
1 parent de9340d commit e2a0bbf

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

autoload/codefmt/mixformat.vim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let s:cmdAvailable = {}
2121
function! codefmt#mixformat#GetFormatter() abort
2222
let l:formatter = {
2323
\ 'name': 'mixformat',
24-
\ 'setup_instructions': 'mix is usually installed with Elixir' .
24+
\ 'setup_instructions': 'mix is usually installed with Elixir ' .
2525
\ '(https://elixir-lang.org/install.html). ' .
2626
\ "If mix is not in your path, configure it in .vimrc:\n" .
2727
\ 'Glaive codefmt mix_executable=/path/to/mix' }
@@ -40,17 +40,20 @@ function! codefmt#mixformat#GetFormatter() abort
4040
endfunction
4141

4242
""
43-
" Reformat the current buffer using ktfmt, only targeting {ranges}.
43+
" Reformat the current buffer using mix format, only targeting {ranges}.
4444
function l:formatter.FormatRange(startline, endline) abort
4545
let l:filename = expand('%:p')
4646
if empty(l:filename)
47+
let l:dir = getcwd()
48+
" Default filename per https://hexdocs.pm/mix/Mix.Tasks.Format.html
4749
let l:filename = 'stdin.exs'
50+
else
51+
let l:dir = s:findMixDir(l:filename)
4852
endif
4953
" mix format docs: https://hexdocs.pm/mix/main/Mix.Tasks.Format.html
5054
let l:cmd = codefmt#formatterhelpers#ResolveFlagToArray('mix_executable')
5155
" Specify stdin as the file
5256
let l:cmd = l:cmd + ['format', '--stdin-filename=' . l:filename, '-']
53-
let l:dir = l:filename == 'stdin.exs' ? getcwd() : s:findMixDir(l:filename)
5457
let l:syscall = maktaba#syscall#Create(l:cmd).WithCwd(l:dir)
5558
try
5659
" mix format doesn't have a line-range option, but does a reasonable job

0 commit comments

Comments
 (0)