stsewd / tree-sitter-rst

reStructuredText grammar for tree-sitter
https://stsewd.dev/tree-sitter-rst/
MIT License
50 stars 7 forks source link

AST depends of order of edit actions. #44

Open Carreau opened 1 year ago

Carreau commented 1 year ago

On https://stsewd.dev/tree-sitter-rst/

list:

 - item2
 - item2

Parses as

document [0, 0] - [4, 0]
  paragraph [0, 0] - [0, 5]
  block_quote [2, 1] - [3, 8]
    paragraph [2, 1] - [3, 8]

But if you edit the first space of the line in front of item2 and add it again, it becomes

document [0, 0] - [4, 0]
  paragraph [0, 0] - [0, 5]
  block_quote [2, 1] - [2, 8]
    paragraph [2, 1] - [2, 8]
  bullet_list [3, 1] - [3, 8]
    list_item [3, 1] - [3, 8]
      body [3, 3] - [3, 8]
        paragraph [3, 3] - [3, 8]

https://github.com/stsewd/tree-sitter-rst/assets/335567/2e0ee656-4354-43f7-b71b-f62b6de062ee

I'll try to have a reproducer via Python API another time. I don't know if it's tree-sitter-rst of tree-sitter bug.

stsewd commented 1 year ago

Hi, sorry for the late reply. This is something I have experience myself while editing files in Neovim. Probably something to do about the parser using (and abusing) an external scanner.

I'll probably need to check if this is a bug on tree-sitter or if there is a better way to communicate to tree-sitter about what nodes should be re-evaluated.

Carreau commented 1 year ago

No need to apologize for the delay tree-sitter-rst have been great to use !

stsewd commented 10 months ago

A way to replicate this using the tree-sitter comand is

npm run parse -- --edit '3,0 1' --edit '3,0 0  ' test.rst
list:

 - item2
 - item2