Syntax Highlighting broken in PHP Code blocks in Assistant responses
Description
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
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?
hey! yeah I am expecting these to show up as code blocks like so:
Code!
Ideally with language-specific syntax highlighting so:
import pandas
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
vs. the sample prompt on Claude web:
screenshot 1
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.
Gotcha. This is a php-specific bug.
Other languages render properly for me, but PHP is broken:
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.
If you notice any other languages not being handled correctly please open issues. Thanks for reporting!
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 🙂
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?
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.
Was just looking for exactly that, excited some changes are coming! Can't wait to try it out.
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
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
Filed an issue upstream:
- https://github.com/tree-sitter/tree-sitter-php/issues/287
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!
@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
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:
- Add the
php_onlygrammar and language to the Zed PHP extension. a. duplicate these lines in extension.toml switchingpath = "php"topath = "php_only"b. add languages/php_only/config.toml c. symlink or adapt languages/php/.scm to languages/php_only/.scm - Add a wrapper for the
language_for_name_or_extensionfunction (e.g.language_for_code_fence_block) which checked a hard-coded grammar override table (e.g. php=>php_only)