sbdchd / neoformat

:sparkles: A (Neo)vim plugin for formatting code.
BSD 2-Clause "Simplified" License
1.97k stars 187 forks source link

Run formatters asynchronously #106

Open uri opened 6 years ago

uri commented 6 years ago

It would be nice if the formatter could run asynchronously. I often save a file and want to navigate elsewhere but the editor is locked on until the formatter finishes. Would be be possible to run the formatter asynchronously? I believe the file would have to be changed to read-only mode between saving and the formatter completing, not sure if this is possible however.

sbdchd commented 6 years ago

Neoformat used to work async, but due to limitations with vim's api, specifically the lack of setbufline(), users couldn't change the buffer.

alem0lars-yr commented 6 years ago

Does it work asynchronously in neovim ?

alok commented 6 years ago

I think neovim has it, and it could be added just for it. This plugin was originally for neovim after all. I'd also like this feature back in.

gryftir commented 6 years ago

@sbdchd if you wanted Neoformat to run async and setbufline was the stumbling block, Vim, as of 8.0.1039 has setbufline https://github.com/vim/vim/commit/b31cf2bb0be95d106bd8eef93cc07550591c1d0d

sbdchd commented 6 years ago

Seems like neovim has nvim_buf_set_lines()

alok commented 6 years ago

Any thoughts on going forward with this?

sbdchd commented 6 years ago

All that needs to happen is https://github.com/sbdchd/neoformat/commit/34d049fd82d86206ef0c153f886c9f5dc84f5494 gets patched onto master, and the job dict gets the current buffer number added so buf_set_lines can be used instead of setline.

Also, killing the job process is no longer needed on buffer switch, since neoformat will keep track of the job's relevant buffer.

shinzui commented 5 years ago

Is there a way to restore the async functionality for neovim users in the meantime?

thedelchop commented 5 years ago

@sbdchd I am happy to do the work you mentioned here: https://github.com/sbdchd/neoformat/issues/106#issuecomment-373434576 to make this async again, but I might need a little more guidance. Do you have time to talk it through a bit more?

sbdchd commented 5 years ago

To add on to what mentioned earlier, we also need to have an ability to switch between the sync and async functionality with variable, e.g., g:neoformat_async = 1 https://github.com/sbdchd/neoformat/issues/106#issuecomment-373434576

This should allow some siloing between the two runner setups and might actually make it easier to add the job_control back.

Patching that previous diff will have to be mostly manual since I am guessing master has changed significantly since then.

quantum-booty commented 2 years ago

Hi, is there any progress on this? thank you!

dlvhdr commented 2 years ago

Any updates or plans?

jesseleite commented 2 years ago

🙏

JoshuaDueck commented 1 month ago

Given that this is still open and hasn't seen any activity in like 2 years, I'm wondering what the current thought is on this. Is there a workaround, or some way people are formatting asynchronously on neovim?

pbogut commented 1 month ago

LSP works async as far as I can tell, and you have tools like efm that wrap linters and formatters with LSP.