tree-sitter-markdown: markdown_inline can't reparse old trees (web-tree-sitter)

I can reproduce this one in the tree-sitter playground on the latest master. From the root:

cd tree-sitter-markdown-inline
tree-sitter build-wasm . && tree-sitter playground

Wait for the playground to open. Type some text with markdown formatting. The tree will not reflect the content.

Select everything you’ve written, cut it, then paste it again. The tree should be correct.

Change anything — even add a space at the very end of the line — and the tree will start to incorrectly shed nodes.

I was able to reproduce this just by pasting and editing the following text:

Lorem ipsum _dolor_ sit amet, consecuetur _adipiscing_ elit. Lorem ipsum _dolor_ sit amet, consecuetur _adipiscing_ elit. Lorem ipsum _dolor_ sit amet, consecuetur _adipiscing_ elit.

After pasting that content, add a space character anywhere, and you’ll notice that the first emphasis node disappears from the tree. The next change (even just deleting the new space) will cause the second emphasis node to disappear, and so on.

This is a symptom of what I observed on my own with the web-tree-sitter bindings: if you call parser.parse(someText, null), everything parses fine; if you call parser.parse(someText, existingTree), nodes get lost. I have no idea if this occurs under the rust or node bindings, but I’ve worked with at least a dozen tree-sitter parsers under web-tree-sitter and this is the first time I’ve observed any symptom like this.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 18

Commits related to this issue

Most upvoted comments

I implemented the changes and it only broke one (unimportant) test, which already doesn’t work for stars. That would be ok for me if it means the parser is more stable.

It seems to work fine. Amazingly, it passes the _lorem ipsum dolor_sit amet_ test I described above. I’ll use it for a few days and let you know if I run into anything else.

Can you checkout the branch https://github.com/MDeiml/tree-sitter-markdown/tree/stable-underscores

I implemented the changes and it only broke one (unimportant) test, which already doesn’t work for stars. That would be ok for me if it means the parser is more stable.