zed icon indicating copy to clipboard operation
zed copied to clipboard

Syntax Highlighting broken in PHP Code blocks in Assistant responses

Open omerbensaadon opened this issue 1 year ago • 14 comments

Description

Image

PHP code blocks in the assistant do not render unless they include <?php ?>

Environment

Zed: v0.161.2 (Zed) OS: macOS 14.6.1 Memory: 32 GiB Architecture: aarch64

omerbensaadon avatar Nov 15 '24 14:11 omerbensaadon

Everything in the Assistant panel is presented as Plaintext/Markdown unmodified so that you can edit/manipulate as desired.

Can you be specific what you are expecting to happen?

notpeter avatar Nov 15 '24 18:11 notpeter

hey! yeah I am expecting these to show up as code blocks like so:

Code!

Ideally with language-specific syntax highlighting so:

import pandas

omerbensaadon avatar Nov 15 '24 18:11 omerbensaadon

Seconding this. Having assistant responses respect code blocks makes the chat far more readable imo

To better explain the need, here is an example where having code blocks would be very appreciated

screenshot 1

screenshot-2024-11-20-16-54-07

vs. the sample prompt on Claude web:

screenshot 1

screenshot-2024-11-20-17-07-01

Note because the assistant panel response includes small snippets of PHP code with no <?php ?> tags present it also doesn't know to render syntax highlighting, compounding the problem. For PHP responses its often a tough wall of text to parse through.

Seltonu avatar Nov 20 '24 17:11 Seltonu

Gotcha. This is a php-specific bug. Other languages render properly for me, but PHP is broken: Screenshot 2024-11-22 at 15 29 22

We use tree-sitter/tree-sitter-php to handle our syntax highlighting for PHP and it appears that this tree-sitter does not correctly highlight snippets. You can see this by pasting that same content into a Zed buffer and selecting PHP from the language selector. It will not highlight correctly, but if you put a <?php and ?> on the first/last lines everything works properly.

@omerbensaadon Zed will attempt syntax highlighting on markdown code blocks in the Assistant for any language it supports (including those provided by extensions). But we not attempt to guess a language if one is not provided immediately following the ``` So for example Shell Scripts or command lines can be tagged with ```bash or ```sh and they will show up as expected.

Screenshot 2024-11-22 at 15 35 32

If you notice any other languages not being handled correctly please open issues. Thanks for reporting!

notpeter avatar Nov 22 '24 20:11 notpeter

FWIW aside from the PHP syntax highlighting bug, I still agree with OP that the code blocks themselves should ideally be rendered out for visual clarity. A dark box around code is much neater/more visually obvious separation in long assistant responses 🙂

Seltonu avatar Dec 01 '24 13:12 Seltonu

Everything in the Assistant panel is presented as Plaintext/Markdown unmodified so that you can edit/manipulate as desired.

Can you be specific what you are expecting to happen?

Is it possible to make it a setting: switch from plaintext to code blocks?

88potatoes avatar Dec 04 '24 08:12 88potatoes

Is it possible to make it a setting: switch from plaintext to code blocks?

There is active development work to restyle the Assistant Panel, including support for displaying code blocks not just with a markdown ```python ... ``` style fence but with a more polished code block widget. Nothing to announce yet, but just wanted to let you know that support for this is coming.

notpeter avatar Dec 04 '24 14:12 notpeter

Was just looking for exactly that, excited some changes are coming! Can't wait to try it out.

adhorodyski avatar Apr 03 '25 11:04 adhorodyski

Was just looking for exactly that, excited some changes are coming! Can't wait to try it out.

Beta waitlist signup is here: https://zed.dev/ai/agent

notpeter avatar Apr 04 '25 22:04 notpeter

Syntax highlighting of snippets remains unfixed for PHP where the <?php ?> tags are missing. As mentioned this is an issue with tree-sitter/tree-sitter-php

Image

Seltonu avatar Aug 06 '25 18:08 Seltonu

Filed an issue upstream:

  • https://github.com/tree-sitter/tree-sitter-php/issues/287

notpeter avatar Sep 09 '25 16:09 notpeter

Hi there! 👋 We're working to clean up our issue tracker by closing older bugs that might not be relevant anymore. If you are able to reproduce this issue in the latest version of Zed, please let us know by commenting on this issue, and it will be kept open. If you can't reproduce it, feel free to close the issue yourself. Otherwise, it will close automatically in 14 days. Thanks for your help!

github-actions[bot] avatar Nov 19 '25 07:11 github-actions[bot]

@omerbensaadon I dont believe this is complete, the lack of syntax highlighting is still present and the upstream issue @notpeter tagged suggested its an issue with Zed's configuration

Image

Seltonu avatar Nov 19 '25 21:11 Seltonu

This is broken in current Zed (0.215.x). PHP code still does not syntax highlight in markdown (md files, markdown preview, agent/assistant code blocks) because it is using the php grammar instead of the php_only grammar.

To support this, I believe would require:

  1. Add the php_only grammar and language to the Zed PHP extension. a. duplicate these lines in extension.toml switching path = "php" to path = "php_only" b. add languages/php_only/config.toml c. symlink or adapt languages/php/.scm to languages/php_only/.scm
  2. Add a wrapper for the language_for_name_or_extension function (e.g. language_for_code_fence_block) which checked a hard-coded grammar override table (e.g. php=>php_only)

notpeter avatar Nov 23 '25 15:11 notpeter