Repository navigation
fix(tui): use php_only grammar for PHP syntax highlighting - #58675
SwastikTripathi wants to merge 3 commits into
Conversation
tree-sitter-php.wasm is the HTML-embedded grammar that requires a <?php opening tag before any highlighting occurs. Switch to tree-sitter-php_only.wasm and its matching nvim-treesitter query so that bare PHP code blocks (without <?php) are highlighted correctly. Fixes anomalyco#58664 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 72 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
There was a problem hiding this comment.
Thanks for tracking down the cause: switching to tree-sitter-php_only.wasm is the right idea. As written, though, this doesn't fix #58664 and it breaks PHP highlighting completely.
How I checked: I loaded parsers-config.ts through opentui's tree-sitter client (highlightOnce) and also rendered the issue's snippet in the TUI with the simulated model. On the base, bare PHP gets no highlights, but <?php code and PHP inside HTML do. With this PR, the client reports No parser available for filetype php for every PHP snippet, including ones that start with <?php. The nvim-treesitter php_only/highlights.scm query doesn't load with this grammar. It also uses #lua-match?, a Neovim-only predicate that the warning at the top of this file is about (it's why the Swift entry doesn't use nvim-treesitter's query). In the TUI, the issue's code block is still plain text (screenshots below).
Keeping the new php_only wasm but keeping the existing upstream query (https://github.com/tree-sitter/tree-sitter-php/raw/refs/heads/master/queries/highlights.scm) works. Bare PHP, <?php code, classes and inline <?php … ?> in HTML all highlighted correctly when I tried it. With that, the old NOTE comment and the two new comment lines can go, so the change stays a one-line wasm swap.
Public API: unchanged.
Related: #58664
| // NOTE: This nvim-treesitter query is currently broken, because the parser is not compatible with the query apparently. | ||
| // "https://raw.githubusercontent.com/nvim-treesitter/nvim-treesitter/refs/heads/master/queries/php/highlights.scm", | ||
| "https://github.com/tree-sitter/tree-sitter-php/raw/refs/heads/master/queries/highlights.scm", | ||
| "https://raw.githubusercontent.com/nvim-treesitter/nvim-treesitter/refs/heads/master/queries/php_only/highlights.scm", |
There was a problem hiding this comment.
This query doesn't load with the php_only grammar: opentui reports No parser available for filetype php, so every PHP block (even ones starting with <?php) loses highlighting. Keeping the previous upstream query https://github.com/tree-sitter/tree-sitter-php/raw/refs/heads/master/queries/highlights.scm with the new php_only wasm works. With it, bare PHP, <?php code and inline PHP in HTML all highlighted in my test.
|
Sharing measurements from my (closed-as-duplicate) #58712, as the bot suggested — including one finding that looks like it matters for this PR. I drove
So the wasm switch in this PR is exactly right — the existing tree-sitter-php highlights query is already fully compatible with the php_only parser (it references no But the query swap looks like a regression: with nvim's |
Dopetaiga's measurements on anomalyco#58675 showed that nvim-treesitter's php_only/highlights.scm causes the parser to fail to register at all ("No parser available for filetype php", 0 highlights). The existing tree-sitter-php highlights.scm is fully compatible with the php_only grammar and yields correct results (7 highlights for <?php blocks, 16 for bare PHP blocks). Keep only the wasm switch. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Thanks for the measurements, Dopetaiga. Your data is conclusive: the wasm switch is correct and the query swap is the regression. I reproduced the same finding: nvim-treesitter's Fixed in |
There was a problem hiding this comment.
The new commit fixes my earlier point. With the php_only grammar and the upstream tree-sitter-php query, code blocks without <?php now highlight in the TUI. Code with <?php, and inline PHP inside HTML, still highlight as before. I checked with opentui's highlightOnce and by rendering the issue's snippet with the simulated model (screenshots below). test/util/filetype.test.ts passes.
Public API: unchanged.
One small thing: the two new comment lines above wasm aren't needed for the fix and can be dropped, so the change stays a one-line swap.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
|
Dropped the two comment lines, the change is now a one-line wasm swap plus the query URL update. Thanks for the detailed review! |
There was a problem hiding this comment.
The two extra comment lines are gone, so this is now a minimal one-line grammar swap. The earlier query problem was fixed in the previous commit.
I ran the issue's reproduction (a tag-less ```php block and a <?php block in one reply, simulated model). On the base only the <?php block is highlighted. With this PR both blocks are highlighted the same way (screenshots below). test/util/filetype.test.ts passes.
Public API: unchanged.
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 72-hour window. Feel free to open a new pull request that follows our guidelines. |






Problem
PHP code blocks without a
<?phpopening tag are not syntax highlighted in the TUI. This was reproduced in #58664.The root cause is that
tree-sitter-php.wasmis the HTML-embedded PHP grammar: it expects a<?phptag to switch from HTML into PHP mode. When a code block contains bare PHP (no<?php), the parser never enters PHP mode and produces no highlight tokens.Fix
Switch to
tree-sitter-php_only.wasm, the bare PHP grammar published alongsidetree-sitter-php.wasmin the same release. This grammar parses PHP directly without requiring an HTML embedding context.The matching highlight query is available from nvim-treesitter at
queries/php_only/highlights.scm(HTTP 200 confirmed).No other files changed.
Added by the opencode bot (AI-generated).
Fixes #58664
Related: #58664