Some overlays not highlighted

I’m trying to add basic JsRender language support, which is yet another templating language that intersperses HTML with {{ ... }} tags. I started with a combination of the Twig example and @codemirror/lang-liquid, and have gotten to the point where syntax highlighting is mostly working; see GitHub repo.

However, I noticed that some overlays (i.e. the HTML parts) are not highlighted in the initial document, but only if the document is longer than 170 lines. When I type anything in one of these unhighlighted overlays, the entire overlay, and subsequent unhighlighted overlays suddenly become highlighted.

There are no JS errors in the console. My editor uses the basicSetup with the defaultHighlightStyle.

I’m happy to provide more details if necessary, but before I do so, I’d like to know if this rings any bells? What could cause this, and is there a way to solve it?

I found that this happens when I fill the initial contents of the editor by creating an EditorView with the doc parameter. If I create the editor empty and then dispatch a transaction with { changes: { from: 0, insert: my_doc } }, the entire document is correctly highlighted.

Is this expected behavior, or does it point to a possible bug?

This sounds like the parser is consuming its entire time budget before it can parse the entire document. However, for a 170-line document, that seems really odd, since the default budget is 3 seconds, in which it should generally be able to parse thousands of lines.

I tried to build your repository but couldn’t reproduce the issue. Can you provide a complete demo?

@marijn: please have a look at GitHub - robbertbrak/jsrender-highlight: Sample repo to illustrate that some overlays are not highlighted to see the issue. You can see that lines 1-18 of the sample document are highlighted properly as HTML, but e.g. line 26-35 are not. Towards the end, starting from line 96, everything is highlighted properly again.

In App.js, if you uncomment line 34, you can see that the whole document is properly highlighted.

From what I can see, the editor loads instantly, so it does not seem like an issue with the parser time budget.

This was a rather subtle bug in the incremental parsing logic for nested parses. This patch should improve it.

1 Like

Perfect, thanks!