Skip to content

Reverse undo operations and rename edits in BulkFileEdits (fixes #344765) - #344776

Open
Ayush Kr Singh (ayushkrsingh946) wants to merge 5 commits into
microsoft:mainfrom
ayushkrsingh946:fix/undo-workspaceedit-folder-rename
Open

Ayush Kr Singh (ayushkrsingh946) wants to merge 5 commits into
microsoft:mainfrom
ayushkrsingh946:fix/undo-workspaceedit-folder-rename

Conversation

@ayushkrsingh946

Copy link
Copy Markdown
Contributor

Fixes #344765

Summary

When an extension applies a WorkspaceEdit that moves a file out of a folder and then renames the folder:

  • On Undo, the inverse operations were executed in forward order, which caused the file to be moved back first. This created the source folder directory, making the subsequent folder rename fail with "target already exists".
  • When one move depends on another, the inverse moves must run in reverse order: the folder first, then the file.

Cause & Solution

  1. In RenameOperation.perform(), undoes were collected and returned in forward application order. We now return new RenameOperation(undoes.reverse(), ...). When undoing, moves execute in reverse order; and when redoing, the inverse of the inverse is reversed again, restoring the original forward order.
  2. In FileUndoRedoElement._reverse(), operations were iterated in forward order for both undo and redo. Reversing this.operations ensures multi-group operations are undone in reverse order and restored on redo.

Verification

  • Added unit tests in src/vs/workbench/contrib/bulkEdit/test/browser/bulkFileEdits.test.ts:
    • rename reverses moves order on undo and restores order on redo
    • undo and redo reverse operation groups order
  • All bulkEdit unit tests pass.
  • npm run precommit hygiene checks pass cleanly.
  • npm run typecheck-client passes cleanly.

Copilot AI balanced review requested due to automatic review settings October 28, 2026 16:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues were identified for the change to undo/redo ordering of dependent file operations.

No open issues 🎉

What changed in this PR

Fixes #344765 by reversing dependent file operations during undo, preventing “target already exists” failures when a workspace edit moves a file out of a folder and then renames that folder.

Changes:

  • Reverse inverse rename operations so undo respects move dependencies.
  • Reverse operation groups for undo and restore their original order on redo.
  • Add regression tests covering rename ordering and mixed operation groups.
File Description
src/​vs/​workbench/​contrib/​bulkEdit/​test/​browser/​bulkFileEdits.test.ts Adds undo/redo ordering tests for dependent renames and mixed groups.
src/​vs/​workbench/​contrib/​bulkEdit/​browser/​bulkFileEdits.ts Reverses inverse renames and operation groups during undo/redo.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

RenameOperation still undoes grouped renames in the wrong order, leaving the target-exists failure unresolved and the undo/redo regression test missing.

1 open issue

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Reversing operation groups leaves inverse renames within a group in forward order, so the reported undo scenario still fails with a target-already-exists error.

2 open issues

Review effort: Max

}

private async _reverse() {
this.operations.reverse();

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Undo of a WorkspaceEdit that moves a file out of a folder and then renames the folder fails with "target already exists"

4 participants