Skip to content

Skip syntax highlighting for read_file outline responses#57287

Merged
MartinYe1234 merged 5 commits into
mainfrom
martin/ai-234-lag-when-expanding-tool-calls
May 21, 2026
Merged

Skip syntax highlighting for read_file outline responses#57287
MartinYe1234 merged 5 commits into
mainfrom
martin/ai-234-lag-when-expanding-tool-calls

Conversation

@MartinYe1234

@MartinYe1234 MartinYe1234 commented May 20, 2026

Copy link
Copy Markdown
Contributor

When read_file returns a file outline instead of full contents, the result is now wrapped in a plain fenced code block rather than tagging it with the file's path.

Previously, the outline was wrapped in a fenced block tagged with the file path (e.g. ```crates/agent/src/tools/read_file_tool.rs). Because the tag contains a slash, the markdown parser routed it through CodeBlockKind::FencedSrc, resolved the file's language by path, and ran the language's tree-sitter parser against the outline on every paint. The outline is structural (e.g. fn foo [L10-20]), not actual source for the file's language, so the parse was both expensive and produced incorrect highlighting.

Because GPUI rebuilds the visible element tree on every window paint, anything that triggers a repaint (cursor blink in the focused message editor, animations, the turn timer, etc.) would re-run the tree-sitter parse on the entire outline, throttling the frame rate while the tool call was expanded.

This change adds an is_outline_response flag in ReadFileTool::run and, when set, passes an empty tag to MarkdownCodeBlock so the renderer sees CodeBlockKind::Fenced (no language). Plain monospace formatting is preserved; the path tag is still used for the non-outline (full file) case.

Adds two regression tests: one asserting the outline path uses an untagged fenced block, and one asserting the full-file path keeps the path tag (so the next person fixing this doesn't accidentally strip the tag everywhere).

Also includes a small markdown-rendering follow-up: MarkdownElementBuilder::push_text was recomputing the base text style (cloning base_text_style and walking the style stack) twice per highlighted token. For a code block with hundreds of highlight tokens, that's hundreds of redundant TextStyle clones per paint. The style stack does not change while runs are being attributed, so the style is now computed once outside the loop and reused.

Closes AI-234

Release Notes:

  • Improved scrolling smoothness in the agent panel when a read_file tool call with a large file outline is expanded.

@MartinYe1234 MartinYe1234 self-assigned this May 20, 2026
@cla-bot

cla-bot Bot commented May 20, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Martin Ye.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

@zed-community-bot zed-community-bot Bot added the staff Pull requests authored by a current member of Zed staff label May 20, 2026
@cla-bot

cla-bot Bot commented May 20, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Martin Ye.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email email@example.com
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

When read_file returns a file outline instead of full contents, wrap the result in a plain fenced code block rather than tagging it with the file's path. The outline is structural (e.g. `fn foo [L10-20]`) and is not valid source for the file's language, so running the language's tree-sitter parser against it on every paint is both expensive and produces incorrect highlighting.

This noticeably improves scrolling smoothness in the agent panel when a read_file tool call with a large outline output is expanded.
@MartinYe1234 MartinYe1234 force-pushed the martin/ai-234-lag-when-expanding-tool-calls branch from 30487d3 to d128b23 Compare May 20, 2026 17:17
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label May 20, 2026
MartinYe1234 and others added 4 commits May 20, 2026 10:30
Asserts that the outline response wraps its markdown in an *untagged* fenced code block (so the markdown renderer doesn't run tree-sitter against pseudo-code outline text on every paint), and that the non-outline path still tags the code block with the file path for syntax highlighting.
`MarkdownElementBuilder::push_text` was computing the base text style (which clones `base_text_style` and walks the style stack) twice per highlighted token: once for the run preceding the highlight and once for the run itself. For a code block with hundreds of highlight tokens, that's hundreds of redundant `TextStyle` clones per paint.

The style stack does not change while runs are being attributed, so compute the style once outside the loop and reuse it. The clone is now only paid when a highlight is actually applied (because `TextStyle::highlight` takes `self` by value).
@MartinYe1234 MartinYe1234 marked this pull request as ready for review May 20, 2026 18:03
@MartinYe1234 MartinYe1234 requested a review from smitbarmase May 21, 2026 15:56
@MartinYe1234 MartinYe1234 added this pull request to the merge queue May 21, 2026
Merged via the queue into main with commit 33eb2d8 May 21, 2026
33 checks passed
@MartinYe1234 MartinYe1234 deleted the martin/ai-234-lag-when-expanding-tool-calls branch May 21, 2026 16:19
TomPlanche pushed a commit to TomPlanche/zed that referenced this pull request Jun 2, 2026
…ies#57287)

When `read_file` returns a file outline instead of full contents, the
result is now wrapped in a plain fenced code block rather than tagging
it with the file's path.

Previously, the outline was wrapped in a fenced block tagged with the
file path (e.g. `` ```crates/agent/src/tools/read_file_tool.rs ``).
Because the tag contains a slash, the markdown parser routed it through
`CodeBlockKind::FencedSrc`, resolved the file's language by path, and
ran the language's tree-sitter parser against the outline on every
paint. The outline is structural (e.g. `fn foo [L10-20]`), not actual
source for the file's language, so the parse was both expensive and
produced incorrect highlighting.

Because GPUI rebuilds the visible element tree on every window paint,
anything that triggers a repaint (cursor blink in the focused message
editor, animations, the turn timer, etc.) would re-run the tree-sitter
parse on the entire outline, throttling the frame rate while the tool
call was expanded.

This change adds an `is_outline_response` flag in `ReadFileTool::run`
and, when set, passes an empty tag to `MarkdownCodeBlock` so the
renderer sees `CodeBlockKind::Fenced` (no language). Plain monospace
formatting is preserved; the path tag is still used for the non-outline
(full file) case.

Adds two regression tests: one asserting the outline path uses an
untagged fenced block, and one asserting the full-file path keeps the
path tag (so the next person fixing this doesn't accidentally strip the
tag everywhere).

Also includes a small markdown-rendering follow-up:
`MarkdownElementBuilder::push_text` was recomputing the base text style
(cloning `base_text_style` and walking the style stack) twice per
highlighted token. For a code block with hundreds of highlight tokens,
that's hundreds of redundant `TextStyle` clones per paint. The style
stack does not change while runs are being attributed, so the style is
now computed once outside the loop and reused.

Closes AI-234

Release Notes:

- Improved scrolling smoothness in the agent panel when a `read_file`
tool call with a large file outline is expanded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants