text: parse prefix extensions incrementally in TextViewState::set_text (#3291) - #3294
Merged
madcodelife merged 2 commits intoSep 28, 2026
Merged
madcodelife merged 2 commits into
madcodelife merged 2 commits into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Thanks for the fix! I pushed a follow-up commit: set_text now appends incrementally only for Markdown. HTML, and any update after a failed parse, still reparses in full, because appending gives wrong results in those cases. I also added tests that check streaming against a full parse. |
madcodelife
enabled auto-merge (squash)
September 28, 2026 14:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
TextView::markdown(id, text)hands its text to the keyed state every frame, throughset_element_text→set_text. When the new text extends the current one,set_textnoticedtext.starts_with(self.text), but only used that to note stream fade before callingincrement_update(text, false, cx), which performed a full replacement reparse:MAX_SYNC_FULL_REPLACE_BYTES(4KB), it parsed synchronously on the UI thread and sent a baseline ack to the background parser;selection_revision, resetting active selections on every streaming token growth;ai-chat), every update costSolution
In
TextViewState::set_text:!self.text.is_empty() && text.starts_with(self.text.as_str()), take the incremental append path matchingpush_str:delta = &text[self.text.len()..];self.text.len();deltatoself.text;self.increment_update(delta, true, cx)so only the trailing block is reparsed without resetting selection or invalidating earlier measured block heights.self.text.is_empty()), text truncation, or non-prefix replacements.Validation
set_text_prefix_extension_updates_incrementally_like_push_strtesting that prefix extensions viaset_textretainselection_revisionandfull_update_revision(unlike replacements).set_text_streaming_matches_push_str_parsed_contentverifying parity between streaming chunks throughset_textvspush_stracross multi-paragraph, inline code, and list structures.cargo test -p gpui-base text::state(81 tests passed).cargo clippy -p gpui-base(0 errors).Closes #3291
Fixes #3291