Currently I’m wrestling with the best way of handling syntax updating whilst typing. At the moment the slow, obvious and safe way to do this is just to recalculate everything highlighting-wise when you’re typing. However for large files this starts to take a noticeable amount of time – this can mean that typing can become really slow and disjointed.
There are a couple of approaches we can take here to work around this issue. Firstly we can attempt to only update the highlights for the text that relate to this change. Therefore if a character is deleted on a line then all the highlights after that point on the same line need to move down one character too. If a line is deleted then all the highlights need to move up one line to stay in alignment. This can be quick but there are tricky edge cases – what happens to the highlight when you delete the middle of a keyword? What happens when you remove a comment end marker? There are many multi-line issues that could make this approach fiddly and difficult to get right.
Second approach could be to farm out the highlighting to a separate thread – get it done in the background and only overlay correct highlighting when it’s been completely recalculated. In the interim you could ‘guess’ what should happen with reasonable accuracy without having to be as exact as above.
Thirdly you could buffer the input somewhat so that all input is captured but the commands fire and the updates happen asynchronously after that. This could also be a model that might work well with an Intellisense a-like API generating model. That will take the most amount of work but it should hopefully leave us in a state where the design is flexible enough for us to add API browsing as part of our development experience.