You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tui: PHP code blocks without <?php are not syntax highlighted #58664
The TUI shows PHP code blocks in assistant messages as plain text unless the snippet starts with <?php. Models usually leave the tag out of short excerpts, so most PHP in a session ends up unhighlighted. Other languages don't have this problem.
Plugins
Only local plugins, none of which touch Markdown or syntax highlighting
Thanks for the clear report. I could reproduce this on 2.1.4.
In a simulated session, the assistant replied with your snippet twice: once as a plain ```php block, and once with <?php added as the first line. The block without the tag renders as plain text, and the one with it is fully highlighted. It still happens on the latest dev (f20760b). The recording and screenshots below show it, and the script below reproduces it.
The likely cause is that the TUI loads tree-sitter's HTML-embedded php grammar, which only starts parsing PHP after <?php. The same tree-sitter-php release also has a php_only grammar for bare PHP. A maintainer still needs to confirm this.
recording.mp4
Reproduction script (drive.ts)
// Reproduces anomalyco/opencode#58664: ```php blocks without `<?php` are not highlighted in the TUI.import{Effect,Stream}from"effect"import{Llm,OpenCodeDriver}from"opencode-drive"constreply=["Without the tag:","","```php","$compiled = parent::getCompiledPath($path);","","if ($this->echoFormat === self::DEFAULT_ECHO_FORMAT) {"," return $compiled;","}","```","","With the tag:","","```php","<?php","$compiled = parent::getCompiledPath($path);","","if ($this->echoFormat === self::DEFAULT_ECHO_FORMAT) {"," return $compiled;","}","```","","Done.",].join("\n")exportdefaultOpenCodeDriver.use({
...(process.env.OC_DEV ? {opencode: {dev: process.env.OC_DEV}} : {}),tui: {recording: true,viewport: {cols: 120,rows: 45}},},({ ui, llm })=>Effect.gen(function*(){yield*ui.screenshot("home")// Answer every model request (including any title request) with the reply.yield*llm.serve(()=>Stream.make(Llm.text(reply)))yield*ui.submit("Show me a PHP snippet")yield*ui.waitFor("Done.")yield*Effect.sleep(3000)yield*ui.screenshot("php-blocks")yield*Effect.sleep(1000)}),)
Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.
I'd like to take this. Root cause: the PHP grammar parses anything outside <?php ... ?> as plain text nodes, so a block without the opening tag produces no highlightable nodes at all. The upstream project ships a dedicated tree-sitter-php_only.wasm variant that treats the whole document as PHP — and the bundled highlights query references no text/program nodes, so it works unchanged against the variant. Plan: point the PHP parser entry at the php_only wasm (blocks that do include <?php still highlight through error-tolerant parsing, losing only the exact tag styling). Will verify by driving the highlight API directly.
@SwastikTripathi#58675 was auto-closed for the PR template, not the change itself. Are you planning to reopen it? If not, I'm happy to pick it up as the one-line tree-sitter-php_only.wasm swap that keeps the existing tree-sitter-php query (per @Dopetaiga's measurements), with credit to you both.
Activity
opencode-agent commentedon Oct 24, 2026
Thanks for the clear report. I could reproduce this on 2.1.4.
In a simulated session, the assistant replied with your snippet twice: once as a plain
```phpblock, and once with<?phpadded as the first line. The block without the tag renders as plain text, and the one with it is fully highlighted. It still happens on the latestdev(f20760b). The recording and screenshots below show it, and the script below reproduces it.The likely cause is that the TUI loads tree-sitter's HTML-embedded
phpgrammar, which only starts parsing PHP after<?php. The same tree-sitter-php release also has aphp_onlygrammar for bare PHP. A maintainer still needs to confirm this.recording.mp4
Reproduction script (drive.ts)
Run it with opencode-drive:
opencode-drive run ./drive.ts. It drivesopencodefrom yourPATH; setOC_DEVto the path of an OpenCode checkout to run that from source instead.Dopetaiga commentedon Oct 24, 2026
I'd like to take this. Root cause: the PHP grammar parses anything outside
<?php ... ?>as plain text nodes, so a block without the opening tag produces no highlightable nodes at all. The upstream project ships a dedicatedtree-sitter-php_only.wasmvariant that treats the whole document as PHP — and the bundled highlights query references notext/programnodes, so it works unchanged against the variant. Plan: point the PHP parser entry at the php_only wasm (blocks that do include<?phpstill highlight through error-tolerant parsing, losing only the exact tag styling). Will verify by driving the highlight API directly.fihaaade commentedon Oct 27, 2026
@SwastikTripathi #58675 was auto-closed for the PR template, not the change itself. Are you planning to reopen it? If not, I'm happy to pick it up as the one-line
tree-sitter-php_only.wasmswap that keeps the existing tree-sitter-php query (per @Dopetaiga's measurements), with credit to you both.