Open Menci opened 4 years ago
This tree-sitter extension works well on updating tree-sitter's tree:
Hello @Menci, Initially I utilized partial updates of syntax tree. But sometimes it broke highlighting after multi-line edits (formatting or copy-pasting), like for example in #19 and #20. So I had decided that it would be better to update entire syntax tree 7495135. I'll look into this, maybe issue is resolved and partial updates will not break highlighting. Thank you for reminding.
I'm currently working on porting your highlighter from vscode to monaco-editor, in order to have fancy highlights in the web. I built a demo here. I used tree.edit
and I didn't find any issue with multi-line editing.
Maybe it's a bug in tree-sitter and already be fixed? Or maybe it's a vscode bug?
Initially I utilized partial updates of syntax tree. But sometimes it broke highlighting after multi-line edits (formatting or copy-pasting), like for example in #19 and #20.
should be reported to tree-sitter ... may be a duplicate of https://github.com/tree-sitter/tree-sitter/issues/1444
So I had decided that it would be better to update entire syntax tree 7495135.
as a "less brutal" solution, we could use incremental parsing for "small" updates (say +-5 characters per edit), and full parse on "large" updates (more than 5 characters were changed)
i guess it should be possible to estimate the size of a changeset, as produced by monaco-editor
edit:
use incremental parsing for "small" updates
seems the issue is not the size of the update, but syntax errors, which break the parse tree on further updates
→ when user is editing, do a full parse every 5 seconds
Initially I utilized partial updates of syntax tree. But sometimes it broke highlighting after multi-line edits
could be fixed in tree-sitter 0.20.1
Tree-sitter supports incremental parsing, which can be accessed via
tree.edit
. But {Syntax Highlighter} just parse the code and generate a new tree every time. This will lost the efficiency advantage from tree-sitter.Also, instad of rebuild every time,
buildDecor
should be done incrementally.https://github.com/EvgeniyPeshkov/syntax-highlighter/blob/5cfdaf7f4c545d49417bb157b6ea73b16fa253b0/src/extension.ts#L200