stsewd / tree-sitter-rst

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

Tree-sitter grammar turns nested directives into `block_quote` #52

Open wjakob opened 5 months ago

wjakob commented 5 months ago

In my continued quest of getting better syntax highlighting for Sphinx RST files, I've noticed that the tree-sitter-rst grammar sometimes turns sequences of nested directives into block_quote nodes (for the second, third, etc., sub-directive). It's possible that TreeSitter considers this to be a syntax/grammar error and that the presented tree is part of the minimum-error resolution strategy.

Screenshot 2024-03-11 at 13 38 22

Anyways, it would be great if the parser could at least accept nested directives, or allow me to inject RST into nodes by adding further queries on top of those provided by the tree-sitter-rst repository. But in this case, the problem is that the tree itself already has the wrong structure.

stsewd commented 5 months ago

This is a problem/limitation with injections on Neovim/TS. Neovim/tree-sitter don't expose an easy way to inject a "dedented range", since RST is sensitive to whitespace, the injected content results in a block quote.

I may try to see if there is a way to solve this from the parser side, like starting to track indents after the first nested indent.

wjakob commented 5 months ago

This would be great, thank you. Many things can be done with queries within Neovim, but this isn't one of them.