-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mix format does not respect local config #236
Comments
The autoformat plugin does not respect the current mix configs and uses the default settings...which breaks a lot of things sadly. Opened a ticket here: vim-autoformat/vim-autoformat#236
My guess is that the contributor who added this support didn't care for that use case. |
Will try to figure this out. |
Apparently this was a bug and fixed in Elixir 1.6.4. Will try it out on the weekend and report back. |
Sadly I can't confirm that 1.6.4 fixed this. I am waiting for a response by the elixir team and will keep you updated here. |
Okay, the problem is that my formatter config has some relative path in it. And elixir will not work with piping in the content and having the formatter have relative paths 😭 . There is no good way to fix this with piping the code into it. The only way forward is to safe the file, run the formatter on the saved file and reload it. |
Conceptually that is not true. There are many formatters that accept an additional filepath argument which is treated as if the stdin would come from that file. Elixir should do that too to solve this. It's the cleanest and most common solution for these kind of problems. |
I've attempted to solve this issue locally with: " Set autoformat command for mix so that we 'cd' into the file's directory
" and then 'cat' the file into 'mix format -' so we get the formatted output
" on std-out but we also get the correct mix formatters context. Import for
" not introducing loads of parens into Phoenix routes, etc.
let g:formatdef_mix_format = "'cd '.expand('%:h').'; cat '.expand('%:t').' | mix format -'" It seems to work though I haven't tested it vigorously. I'm also not sure how portable it is but it seems fine on my Ubuntu/neovim set up. I've been experiencing the issue with Elixir/mix 1.8. |
@michaeljones thanks for this. Works on my setup like a charm 👍 |
See the full discussion here: vim-autoformat/vim-autoformat#236
I'm afraid I've not had time to test this in anger and I'm worried that it is going to use the contents of the file on disk rather than the contents of the buffer. I don't see a way to get |
My fears were confirmed. If you delete a line and then save the file, the line comes back because the formatter runs before the save and uses the file on disk. This is confirmed by The code I now have is: " Try to find the closest '.formatter.exs' to the file currently being edited.
" If we find one, then pass that as context to the `mix format` command.
" Withouth this the `mix format -` has no context for the formatting so and
" cannot apply local project rules.
function! g:BuildMixFormatLocalCmd()
let l:format_file = findfile('.formatter.exs', '.;')
if format_file != ''
return 'mix format --dot-formatter ' . format_file . ' -'
else
return 'mix format -'
endif
endfunction
let g:formatdef_mix_format = "g:BuildMixFormatLocalCmd()" The |
Sadly the
mix format -
does not respect my local config for the formatter. It uses the default mix format settings. Is this a known problem? Do I have it misconfigured locally?The text was updated successfully, but these errors were encountered: