I am experimenting with syntax highlighting (using decorations, very similar to lint example). For smaller document it works fine. But when document is a bit larger it takes longer time to load it. Because it is doing everything (loading document and highlight), so ‘tasks’ that need to be done are sync. A lot of editors split tasks, so user has better experience. User can see that ‘it is doing something’ and have incremented results, instead of waiting longer time with ‘nothing state’ and then ‘boom, here we go with everything’.
My question is, is it possible to split tasks? Or make them async? Or enable plugins ‘onload’. If so how?
In this simple scenario there would be 3 tasks:
- load the editor
- load hole document
- when editor is ready, run syntax highlighting (or enable syntax plugin)
- then words are highlighted, show in toolbar how word are in document or so.
Thanks for an advise.
There’s no feature for this in the library, but you can implement this against the existing interface. You could try something like this:
- The plugin has a plugin view that takes care of scheduling work and restarting work when the view is updated before it finishes.
- Whenever highlighting work is finished, if it changed something, fire a transaction that passes the new highlighting data to your plugin, so that the display is updated with new decorations.
Or, alternatively, make your highlighting incremental (you might get some ideas from this blog post) so that it doesn’t need to to so much work in a typical transaction, even if the document is big.
Whenever highlighting work is finished, if it changed something, fire a transaction that passes the new highlighting data to your plugin, so that the display is updated with new decorations.
If you’re out googling and come across this thread: as as spark of inspiration for how to do this, it worked great for me to do something along the likes of:
to trigger an “empty” transaction. This of course doesn’t carry any data over to the plugin, but it did enough for me.