Add ability to do synchronous formatting
Closed this issue · 9 comments
It would be useful to have the option to format synchronously with something like FormatSync
. I work on a pretty large mono repo with a lot of generated protobuf code and sometimes goimports
takes quite a long time to run which often results in the Buffer changed while formatting, skipping
message or when the format is successful it can go unnoticed.
Having a FormatSync
would also let users have the following autocommand which would enable formatting on :wq
(#98)
autocmd BufWritePre *.go FormatSync
If you want synchrony formatting, could you not just use formatprg
?
I guess that's true but this library really simplifies the configuration part. For formatters that don't use stdin, you'd have to define a function somewhere and then set formatexpr
for each filetype whereas this plugin is can all be defined in one place in a consistent manor.
I have FormatWriteSync
working locally, if you're interested I can open a PR. Likewise if it's not something you think this plugin should support I completely understand and we can close this ticket!
I guess that's true but this library really simplifies the configuration part.
that's true :+1
Open the PR! I have nothing against supporting it, as long as it doesn't add a bunch of complexity.
I think it looks good for most cases but it doesn't solve the problem of opening a file, making a change that needs formatting and then running :wq
. If the format isn't instant you end up with an unformatted file which is a bit of a pain.
It almost needs something like a sync on exiting neovim to wait for any outstanding async format jobs?
That would be a neat feature - I'll look into it tomorrow.
I'm not sure how to implement that but if it's a pain I don't think it should hold up the current PR!
ofc - ill merge the current PR in the next week/two weeks to see if anyone has an objection and ill make this feature into another PR if i deem it feasible
closing this in favor of a new issue