Skip to content

fix(tui): highlight PHP blocks that do not open with <?php - #58712

Closed
Dopetaiga wants to merge 1 commit into
anomalyco:devfrom
Dopetaiga:fix/tui-php-highlight-without-open-tag
Closed

Dopetaiga wants to merge 1 commit into
anomalyco:devfrom
Dopetaiga:fix/tui-php-highlight-without-open-tag

Conversation

@Dopetaiga

Copy link
Copy Markdown

Fixes #58664

Problem

The TUI shows PHP code blocks as plain text unless the snippet starts with <?php. Root cause: the PHP grammar parses anything outside <?php ... ?> as plain text nodes, so a block without the opening tag — how models usually emit short PHP excerpts — parses to zero highlightable nodes. Other languages are unaffected because their grammars don't have this in-document tag structure.

Fix

Point the PHP parser entry at the upstream tree-sitter-php_only.wasm variant (same release, v0.24.2), which treats the whole document as PHP code. Two reasons this is safe:

  • The bundled highlights query references no text/program nodes, so it runs unchanged against the variant.
  • Blocks that do open with <?php highlight identically under either parser (measured below).

One URL change plus the rationale comment; the query source is untouched.

Verification (local, driving TreeSitterClient directly with the real wasm downloads)

Highlighted ranges for the issue's snippet vs a tagged version, current parser vs the fix:

parser block without <?php block with <?php
tree-sitter-php.wasm (current) 0 — the reported bug 7
tree-sitter-php_only.wasm (fix) 16 7

packages/tui typecheck (bun 1.4.4): no type errors across the package's projects.

The PHP grammar parses anything outside <?php ... ?> as plain text
nodes, so a code block without the opening tag — how models usually
emit short PHP excerpts — produced zero highlightable nodes. Point the
PHP entry at the php_only wasm variant, which treats the whole
document as PHP; the bundled highlights query references no text or
program nodes, and blocks that do open with <?php highlight
identically under either parser.
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Oct 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

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.

@opencode-agent opencode-agent Bot closed this Oct 24, 2026
@opencode-agent

Copy link
Copy Markdown
Contributor

Thanks for the fix and for measuring the highlight ranges before and after, @Dopetaiga!

I think this duplicates #58675, which is already open for #58664 and makes the same switch to tree-sitter-php_only.wasm.

One difference may matter: #58675 also replaces the highlights query with nvim-treesitter's php_only/highlights.scm. This PR keeps the existing tree-sitter-php query, which the code comment says is the one that works with this parser, and you showed it still highlights correctly. It would help a lot if you shared that finding on #58675, along with your results table, or tested that pull request's query change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tui: PHP code blocks without <?php are not syntax highlighted

1 participant