You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you ran any formatter that does not take a stdin (Also see #78 and #64) then you will run into problems where you won't see your formatted code changes.
The unfortunate part is that you will have to save the file and then run :edit! to see those changes, since those formatters will only work on files saved on the system.
You will need winsaveview() and winrestview() so that the cursor and window position is saved before formatting the file. silent is needed so it does not error if it fails, we want to handle it gracefully.
If you are using an auto-save plugin and you want to format the current buffer with a formatter that does not take stdin input, you can try this approach:
localfunctionefm_fmt_with_auto_save()
-- check if efm is available in the current buffervim.lsp.buf.format({ name="efm", async=false })
vim.api.nvim_feedkeys("n", "n", true)
vim.api.nvim_feedkeys("<CR>", "n", true)
vim.cmd("edit!")
end
Problem
If you ran any formatter that does not take a
stdin
(Also see #78 and #64) then you will run into problems where you won't see your formatted code changes.The unfortunate part is that you will have to save the file and then run
:edit!
to see those changes, since those formatters will only work on files saved on the system.Solution
One solution would be to run the format command after save, for example (for a better version see the last code block):
You will need
winsaveview()
andwinrestview()
so that the cursor and window position is saved before formatting the file.silent
is needed so it does not error if it fails, we want to handle it gracefully.Add this to your
on_attach
:Or to your autocmd to format on save:
Final Solution Code
We can take this one step further and account for when a formatter has
formatStdin = false
and only call:edit!
or just format as is.The text was updated successfully, but these errors were encountered: