carry text edits until successful migration#132
Conversation
⚡ Risk Assessment —
|
| Files | Summary |
|---|---|
Text Edit Change Tracking SystemAnyText/AnyText.Core/ItemEqualityComparer.csAnyText/AnyText.Core/TextEdit.csAnyText/AnyText.Core/ChangeTracker.cs |
Implements persistent edit accumulation with merge logic: new ItemEqualityComparer compares string arrays element-bywise, TextEdit gains equatable implementation, ChangeTracker converts to List-based storage with adjacent/overlap merge handling, tracks original text for each edit to enable intelligent merging. |
Parser IntegrationAnyText/AnyText.Core/Parser.cs |
Updates parser to call AddEdit() per edit instead of SetEdits(), moves Reset() call after input capture so edits survive migration failures, applies edits incrementally then resets on successful migration. |
Utility AdditionsAnyText/AnyText.Core/ParsePosition.cs |
Adds ToString() override for debugging convenience. |
Debug Safety ChecksModels/Models/ModelElement.cs |
Adds #if DEBUG guardrails detecting parent hierarchy loops and self-referencing during parent traversal. |
Sequence Diagram
sequenceDiagram
participant U as User
participant P as Parser
participant CT as ChangeTracker
participant M as Matcher
U->>P: Update(edit1)
P->>CT: AddEdit(edit1, input)
CT->>CT: Store edit + original text
P->>M: Apply(edit1)
M-->>P: migration result
alt migration fails
P-->>U: Return failed result
note over CT: Edits retained for next attempt
else migration succeeds
P->>CT: Reset()
end
U->>P: Update(edit2)
P->>CT: AddEdit(edit2, input)
CT->>CT: Merge with edit1 if adjacent/overlap
Dig Deeper With Commands
/review <file-path> <function-optional>/chat <file-path> "<question>"/roast <file-path>
Runs only when explicitly triggered.
| var updatedText = insertion.Apply(adjacentEdit.NewText); | ||
| var overlapEnd = UpdateEndPosition(edit.End, adjacentEdit.EndAfterEdit, edit.Start); | ||
| _edits[editIndex] = new TextEdit(adjacentEdit.Start, overlapEnd, updatedText); | ||
| // TODO: update oldText |
There was a problem hiding this comment.
Overlapping edit merge leaves stale original text behind
In the overlap branch, the tracker rewrites _edits[editIndex] but never updates _oldTexts[editIndex]. That breaks the whole "carry edits until a successful migration" flow: a later edit can compare against the wrong pre-edit content and either drop a real change or keep an obsolete one.
Update _oldTexts[editIndex] when collapsing overlapping edits. Easiest fix is to recompute the merged old text for the new combined span, or explicitly carry forward the correct original slice before replacing _edits[editIndex].
| var hash = obj.Length.GetHashCode(); | ||
| for (int i = 0; i < obj.Length; i++) | ||
| { | ||
| hash ^= 23 * hash + obj[i].GetHashCode(); |
There was a problem hiding this comment.
Array comparer crashes on null entries
GetHashCode assumes every array element is non-null and calls obj[i].GetHashCode() directly. This comparer is generic and used for string arrays, so a single null element will throw during hashing instead of behaving like Equals, which already tolerates null arrays.
Use a null-safe hash, e.g. hash = (hash * 23) ^ (obj[i]?.GetHashCode() ?? 0); and mirror that in TextEdit.GetHashCode() if you want the new equality implementation to stay robust too.
Actionable Comments Posted: 2🧾 Coverage Summary✔️ Covered (9 files) |
Summary by MergeMonkey