Repository navigation
fix(chat): preserve #file reference when editing text before it - #333965
Justin Chen (justschen) merged 9 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Enclosing replacements can incorrectly trigger a second edit that deletes unrelated text.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Preserves inline chat references when unrelated edits shift their offsets.
Changes:
- Detects whether edits overlap a reference.
- Recomputes ranges after non-overlapping edits.
- Adds regression tests for related editing scenarios.
File summaries
| File | Description |
|---|---|
chatDynamicVariables.ts |
Adds overlap detection and range recovery. |
chatVariables.test.ts |
Adds reference-editing regression tests. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
82e9a7d to
21dda2f
Compare
21dda2f to
65fd2f1
Compare
…eference-before-edit # Conflicts: # src/vs/workbench/contrib/chat/browser/attachments/chatDynamicVariables.ts
…re-edit' into fix/preserve-file-reference-before-edit
Justin Chen (justschen)
left a comment
There was a problem hiding this comment.
thanks!!!
79bd6ec
|
Justin Chen (@justschen), Giuseppe Cianci (@Giuspepe), roblourens — I’ve addressed the CI failure. This dismissed your prior approvals, so could you please re-review and retrigger the CI when you get a chance? Thanks! |
…erence-before-edit
Head branch was pushed to by a user without write access
|
Hi Justin Chen (@justschen) , thanks for the review! I’ve resolved the merge conflicts. Could you please retrigger CI and re-review the PR? |
|
Hi Justin Chen (@justschen) — just checking in on this PR now that the merge conflicts are resolved and it’s ready for review. When you have a chance, could you take another look? Let me know if anything else is blocking it. Thanks! |
|
Hi roblourens, Giuseppe Cianci (@Giuspepe) — the PR is ready for review again. When you have a chance, could you please take another look? Thanks! |
* port(chat-ui): preserve #file reference when editing text before it (#394) Upstream d750fe2 (microsoft#333965), applied clean with its tests. Typing before an existing #file attachment silently deleted the attachment. Adds touchesReference and findReferenceRangeForNonOverlappingEdit. * port(chat-ui): highlight generic tool output by content type (#394) Upstream 63acf08 (microsoft#333923). chatInputOutputMarkdownProgressPart.ts applied clean; the chatToolOutputContentSubPart.ts hunk was hand-applied because the fork's adjacent-code-part loop predates upstream's refactor. The agentHost stateToProgressAdapter.ts hunk and its test are dropped (Agent Host only). Our patent tools return large JSON payloads into exactly this part. * port(chat-ui): fix IME handling in the chat find widget (#394) Upstream b9861ad (microsoft#332950), applied clean with its tests. Composition input (CJK) broke search in the transcript find widget. * port(chat-ui): fix transcript Find keybindings (#394) Upstream cefc831 (microsoft#333135). chatFindActions.ts, chatFindWidget.ts, chatListWidget.ts and the find tests applied clean; the chatListWidget.test.ts hunk was hand-applied because that test file is diverged. Enter/Escape/F3 inside the transcript find widget went to the generic tree find instead of chat Find. * port(chat-ui): configurable paste-to-attachment threshold and Insert in Prompt (#394) Upstream e1801a0 (microsoft#331978). chatPasteProviders.ts, chatCopyActions.ts, constants.ts, chatAccessibilityHelp.ts, the chat.shared.contribution.ts configuration registration and the paste tests all applied clean. The src/vs/sessions hunks are left out: the fork has no caller of createPastedTextArtifact there, and sessions files belong to the deferred wave W. * port(chat-ui): remove the line requirement for paste attachments (#394) Upstream 36053db (microsoft#335100), hand-applied: the fork's chatPasteProviders.ts lacks the GitHub-URL pattern that surrounds the hunk, and its chatAccessibilityHelp.ts and both test files are behind upstream's base. A short paste now becomes an attachment on character count alone, so pasting a single-line claim works like pasting a multi-line one. * port(chat-ui): reuse text buffers for checkpoint replay (#394) Upstream 903d0d0 (microsoft#336095), applied clean with its tests. Checkpoint restore rebuilt a text model per replayed edit. * port(chat-ui): constrain symbol tools to the active workspace (#394) Upstream d8cfdc7 (microsoft#333144), applied clean with its tests. renameTool and usagesTool no longer reach outside the active workspace folder.
|
Anupam Kumar (@AnupamKumar-1) thank you so much for fixing this bug! It has been annoying me for weeks. I really appreciate the effort you put towards resolving it! Cheers! |
|
nice work |
Fixes #333941
Editing text before an inline
#file:reference (for example, pressingBackspace immediately before it or retyping an earlier word) could delete
the reference entirely.
The existing recovery logic handled replacements that enclosed the reference,
but did not preserve the reference when unrelated edits changed its offset.
Such edits could therefore fall through to the removal path.
This adds a
touchesReferencecheck to distinguish edits that overlap thereference from edits that occur outside it. For non-overlapping edits, the
reference range is recomputed from the net offset delta instead of removing
the reference. Edits that touch the reference continue to remove it.
Added regression tests covering deletion before the reference, replacement
before it, deletion touching its first character, and edits both before and
after the reference in a single change event.
Manually verified the behavior with a real
#file:reference in a runningdev build.
How to test
Compare the ownership section of.#, pick a file so#file:README.mdis inserted inline, then continue typingwith the current draft.#file:README.mdreference is preserved instead of being deleted.Also covered by the added tests in
chatVariables.test.ts(delete-before, replace-before, delete-touching-first-char, edits-before-and-after).