Code folding breaks parsing of syntax tree

I have implemented a custom lezer grammar and added an view plugin extension to display a button in the editor if the node name matches a specific name.

Under normal circumstances, it works fine and the widget shows properly. However, when I fold the code in the editor, it appears the syntax tree does not know how to continue parsing the document with the folded code, and then starts from the @top entrypoint grammar token, which means the node I am looking for appears twice in the syntaxTree.iterate() call instead of once. I’m not sure if it is something wrong with my lezer grammar or if this is a bug in the interop between the folding decorator and the language parsing.

My grammar is here and the inline widget implementation is here

Parsing (at least with @lezer/lr, which appears to be what you’re using) shouldn’t even have access to folding information, so maybe there’s something else going on?

Yeah I think it has something to do with this for loop over the visible range. Removing that seems to have solved the issue for me.