Paul Jolly wrote:
> Within the channel-based plugin govim > (https://github.com/govim/govim), the bulk of functionality is > triggered by user actions in Vim. > > However, certain events are triggered entirely independently of Vim, > for example a list of diagnostics arriving from an LSP server, the LSP > server asking govim to show an error message. There are others. > > When handling these non-Vim triggered events, any call from govim to > Vim is effectively racing (i.e. in a race condition) with whatever Vim > might be doing at the time. For example, we might happen to call from > govim -> Vim while Vim is in the middle of handling a listener_add > callback that itself calls ch_evalexpr which results in a call Vim -> > govim. > > One thing we're not clear on is whether we should be "scheduling" > certain things in Vim. The channel docs > (https://github.com/vim/vim/blob/master/runtime/doc/channel.txt) > highlight that we should be checking what mode the user is in, but I > don't think this handles the case described. > > What do I mean by scheduling? As I understand it, if when handling a > non-Vim triggered event we instead made a call into Vim that did > something like: > > timer_start(0, { -> dostuff() }) > > then dostuff() will be "scheduled" by Vim "at a convenient time". > > Would this approach work? > > We're seeing some tests randomly failing and this "scheduling" problem > is our current hypothesis. But our understanding here is vague, so any > suggestions/guidance appreciated. Vim will try to handle messages as soon as possible, but in a "safe" situation. That is usually when waiting for a user to type. But it might still be halfway a command, such as when editing the command line, in Insert mode or after an operator such as "d". Some things should be safe, such as using popup_notification() to show a message. But something like ":normal" or "feedkeys()" will interfere with what the user is doing. It's up to the plugin to detect this and schedule doing the work later. Using a timer won't help much, since you do not know when the state has changed. You can use autocommands, e.g.: if mode() =~ [iR] au InsertLeave * call DoTheWork() endif There is no generic autocommand event for changing mode, perhaps that is want you are looking for? Or a "NormalMode" event for when nothing is pending? That may take a while though. -- hundred-and-one symptoms of being an internet addict: 232. You start conversations with, "Have you gotten an ISDN line?" /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org /// -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/201909101805.x8AI5YbV005331%40masaka.moolenaar.net.
