Skip to content

acp_thread: Await Tree-sitter parsing before building agent panel diffs#49101

Merged
benbrandt merged 1 commit intozed-industries:mainfrom
chenwuji2000-cyber:fix/agent-panel-syntax-highlighting
Feb 16, 2026
Merged

acp_thread: Await Tree-sitter parsing before building agent panel diffs#49101
benbrandt merged 1 commit intozed-industries:mainfrom
chenwuji2000-cyber:fix/agent-panel-syntax-highlighting

Conversation

@chenwuji2000-cyber
Copy link
Contributor

@chenwuji2000-cyber chenwuji2000-cyber commented Feb 13, 2026

Summary

Fixes #48684

  • Await parsing_idle() after set_language() in both Diff::finalized() and PendingDiff::finalize() so that tree-sitter parsing completes before buffer snapshots are taken for excerpts
  • Without this, the 1ms sync parse timeout almost always expires for non-trivial files, causing excerpts to be created with empty syntax trees and missing syntax highlighting

Root Cause

When the agent panel creates or finalizes a diff, it creates a new Buffer, calls set_language() (which triggers async tree-sitter parsing), then immediately proceeds to take buffer snapshots and create excerpts without waiting for parsing to complete. The sync parse timeout is only 1ms in production (buffer.rs:1138), so large files almost always fail the sync parse and fall back to async parsing — but no one awaits the async parse before building the diff.

Fix

Add buffer.update(cx, |buffer, _| buffer.parsing_idle()).await after set_language() in both code paths (Diff::finalized() and PendingDiff::finalize()). This is the same pattern already used in buffer_diff.rs:1728-1731.

Test plan

  • cargo test -p acp_thread — all relevant tests pass
  • ./script/clippy — no warnings
  • Manual test: open agent panel, ask it to generate a Python file with multiline strings ("""), verify syntax highlighting is correct after diff is finalized

Release Notes:

  • Fixed missing syntax highlighting for multiline strings in agent panel diffs

🤖 Generated with Claude Code

Wait for `parsing_idle()` after `set_language()` in both `Diff::finalized()`
and `PendingDiff::finalize()` so that syntax highlighting is available when
excerpts are created, fixing missing highlights for multiline strings.

Co-Authored-By: Claude <noreply@anthropic.com>
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 13, 2026
@zed-community-bot zed-community-bot bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Feb 13, 2026
@maxdeviant maxdeviant changed the title fix: await tree-sitter parsing before building agent panel diffs acp_thread: Await Tree-sitter parsing before building agent panel diffs Feb 13, 2026
@chenwuji2000-cyber
Copy link
Contributor Author

#48684 (comment)

Manual test passed. See this comment.

@SomeoneToIgnore SomeoneToIgnore added the area:ai Improvement related to Agent Panel, Edit Prediction, Copilot, or other AI features label Feb 13, 2026
Copy link
Member

@benbrandt benbrandt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@benbrandt benbrandt enabled auto-merge (squash) February 16, 2026 14:33
@benbrandt benbrandt self-assigned this Feb 16, 2026
@benbrandt benbrandt merged commit cbf03f5 into zed-industries:main Feb 16, 2026
47 checks passed
rtfeldman pushed a commit that referenced this pull request Feb 17, 2026
…fs (#49101)

## Summary

Fixes #48684

- Await `parsing_idle()` after `set_language()` in both
`Diff::finalized()` and `PendingDiff::finalize()` so that tree-sitter
parsing completes before buffer snapshots are taken for excerpts
- Without this, the 1ms sync parse timeout almost always expires for
non-trivial files, causing excerpts to be created with empty syntax
trees and missing syntax highlighting

## Root Cause

When the agent panel creates or finalizes a diff, it creates a new
`Buffer`, calls `set_language()` (which triggers async tree-sitter
parsing), then immediately proceeds to take buffer snapshots and create
excerpts **without waiting for parsing to complete**. The sync parse
timeout is only 1ms in production (`buffer.rs:1138`), so large files
almost always fail the sync parse and fall back to async parsing — but
no one awaits the async parse before building the diff.

## Fix

Add `buffer.update(cx, |buffer, _| buffer.parsing_idle()).await` after
`set_language()` in both code paths (`Diff::finalized()` and
`PendingDiff::finalize()`). This is the same pattern already used in
`buffer_diff.rs:1728-1731`.

## Test plan

- [x] `cargo test -p acp_thread` — all relevant tests pass
- [x] `./script/clippy` — no warnings
- [x] Manual test: open agent panel, ask it to generate a Python file
with multiline strings (`"""`), verify syntax highlighting is correct
after diff is finalized

Release Notes:

- Fixed missing syntax highlighting for multiline strings in agent panel
diffs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ai Improvement related to Agent Panel, Edit Prediction, Copilot, or other AI features cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Claude Code: Partial edit of large Python multiline string breaks syntax highlighting in agent panel

3 participants