tree-sitter / tree-sitter-php

PHP grammar for tree-sitter
MIT License
156 stars 52 forks source link

why isn't php injected via the html parser #178

Closed Hippo0o closed 10 months ago

Hippo0o commented 1 year ago

PHP files are just html with php code blocks in it. So why does this parser work the other way around combining html around the php code blocks to inject html? Would'nt it make more sense if the html parser injected php?

I'm asking because i was investigating issues i have using neovim and files that mainly have html with some php code in it.

calebdw commented 10 months ago

PHP is a templating engine which can be used for any type of text file---the treesitter query injects html because that's the most common, but the node itself is called text in the grammar which is indicative of this. Additionally, it shouldn't be the html parser's responsibility to analyze .php files.

I'm asking because i was investigating issues i have using neovim and files that mainly have html with some php code in it.

What issues were you having?

Hippo0o commented 10 months ago

@calebdw i wrote about it here https://github.com/nvim-treesitter/nvim-treesitter/pull/4653#issuecomment-1593091425

The main issue seems to be that the @combined query will combine the ranges of the whole text node which collides with the ranges of the php nodes inbetween. And because of the ordering or smth the html ranges overshadow all inbetween.

Hippo0o commented 10 months ago

so the problem primarly lies with the neovim treesitter implementation of querying injections

calebdw commented 10 months ago

Hmm, I don't see any issues with the Neovim hightlighting?

image

so the problem primarly lies with the neovim treesitter implementation of querying injections

Sounds like this issue can be closed then

Hippo0o commented 10 months ago

Thanks for giving me an answer.