stsewd / tree-sitter-rst

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

RST grammar not injected into sub-directives #51

Open wjakob opened 6 months ago

wjakob commented 6 months ago

The current version of the tree-sitter RST parser does not process RST grammar embedded into directives like .. warning::, .. note::, etc. See here for an example of such a document and the parse tree shown in NVIM. Note the absent syntax highlighting of the reference.

Screenshot 2024-03-08 at 22 06 48

Curiously, it works when the directive is further annotated:

Screenshot 2024-03-08 at 22 08 00

PS: I am skeptical if the document element makes sense occurring within the tree in this way. When I try to add a custom tree-sitter rule that matches on this element to manually inject the RST grammar into document, I get an error message from NVIM saying that the following structure is impossible.

Screenshot 2024-03-08 at 22 11 42
stsewd commented 6 months ago

PS: I am skeptical if the document element makes sense occurring within the tree in this way. When I try to add a custom tree-sitter rule that matches on this element to manually inject the RST grammar into document, I get an error message from NVIM saying that the following structure is impossible.

That's because document is part of the injected tree, not from the original one. Neovim basically injects rst inside rst.

Curiously, it works when the directive is further annotated:

That's probably a bug in the injection queries from nvim-treesitter, I'll look into that in following days/weeks.

wjakob commented 6 months ago

That's because document is part of the injected tree, not from the original one. Neovim basically injects rst inside rst.

Makes sense!

That's probably a bug in the injection queries from nvim-treesitter, I'll look into that in following days/weeks.

Great, thank you! ❤️