Better async#57
Conversation
|
Actually, you can not async everywhere. In neovim, you can only be async when calling vim.system or something to create a new process, any lua code in the neovim is sync. Using plenary is to avoid the callback hell, in this plugin, it sems that using plenary or not are both OK, because this plugin is simple enough. In the original code, I tried to make all the time consuming jobs async, there jobs are mainly fetching resources from internet. The jobs using sync should be executed very quickly, such as Coroutine is a good way to write code for this plugin, but this actually not solve the problem you mentioned. Or if i misunderstand something, can you give a more detailed explanation? |
I know. Maybe my word choice wasn't the best. This PR makes all calls to external process async, it completely avoids the user of any blocking
I know. But it's not necessary. Under the hood, plenary uses lua coroutines to avoid callback hell with luv. This PR does the same while removing the dependency on plenary.nvim.
It was not a huge repo, it was happening on my nvim-config repo and only on windows. Git it's just that much slower in windows, it has nothing to do with the repo size. The same repository on a unix-like system felt instantaneous, which means that making the code sync shouldn't be a problem in those cases and it's a win-win situation.
It does. That's how plenary (or any lua plugin's async code) works under the hood. It removes the dependency in plenary.nvim and, using it everywhere there are external processes being executed, stops Neovim from being blocked. You can take a look at this post to learn more about how coroutines work with Neovim's async code: https://gregorias.github.io/posts/using-coroutines-in-neovim-lua/ |
Always create a cache when initializing source or when the previous cache is invalidated. In completion, check if the cache is available. If it is, use it. If it is not, asynchronously wait for it to be available.
|
I implemented the changes you requested. Let me know if you would like me to modify anything else. I could rebase the commits into a single one if you prefer after your review. |
|
Nice work! Thank you very much! |
Problem:
The plugin isn't truly async everywhere. There are calls for
syncon a plenary job that callvim.waitunder the hood, which blocks the editor until the jobs has finished it's execution. This may not be a problem in unix-like systems, but it is in Windows.This, plus the fact that the plugin delays the execution of this jobs until
InsertEnterresults in Neovim being blocked for a couple of seconds onInsertEnterthe first time after opening Neovim.Solution:
Ditch the plenary.nvim dependency altogether and use the builtin
vim.systemand lua coroutines to have async code everywhere.As a consequence of this change I also ended up removing the
asyncconfig option and defaulting to using async always (since there is no cost to doing so).I would also prefer to eagerly start the cache related jobs earlier, but didn't change the code to do so because that's not my decision to make. Since they are async, they won't block the user in any case. This will allow the plugin to always offer completions results on insert mode, even when defaulting to async always.