You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Undo of a WorkspaceEdit that moves a file out of a folder and then renames the folder fails with "target already exists" #344765
Does this issue occur when all extensions are disabled?: An extension has to apply the edit (workspace.applyEdit). The Undo that fails is VS Code's own.
VS Code Version: 1.140.0. The code below is unchanged on main (915c6faed9c).
OS Version: macOS (Darwin 27.0.0)
Steps to Reproduce:
In a workspace with a folder a that contains a file a/b.txt, apply this edit from an extension. It moves the file out of the folder, then renames the folder:
The edit applies: the workspace now has b.txt and the folder c.
Focus the Explorer and run Edit > Undo.
Expected: Undo renames c back to a, then moves b.txt back into it.
Actual: Undo moves b.txt back first, which creates a new folder a. Renaming c back to a then fails with "target already exists".
Cause: FileUndoRedoElement._reverse() in src/vs/workbench/contrib/bulkEdit/browser/bulkFileEdits.ts performs the inverse operations in the original order, for Undo and for Redo. RenameOperation.perform() also collects its inverse moves in the original order. When one move depends on another, as here, the inverse moves must run in the reverse order: the folder first, then the file.
An extension can't avoid this by ordering the moves. If it renames the folder first and then moves the file from c/b.txt, Undo renames c back to a first, and then moves b.txt into a new folder c. Moves that depend on each other have to be undone in the reverse order of their application.
We hit this in an extension's automated test, where a language server's rename returns such an edit for a file and its folder. The steps above are its minimal form.
Thanks for creating this issue! It looks like you may be using an old version of VS Code; the latest stable release is 1.143.1. Please try upgrading to the latest version and checking whether this issue remains.
This is still the case on main (915c6faed9c, 2026-10-28), which is newer than 1.143.1: FileUndoRedoElement._reverse() and RenameOperation.perform() in bulkFileEdits.ts haven't changed. #344772 fixes it.
I investigated this issue and verified the root causes:
In RenameOperation.perform(), inverse moves (undoes) were being returned in forward application order. When an edit moves a file out of a folder and then renames the folder, undoing in original order attempts to move the file back first (which creates the folder before the folder rename can occur), causing the folder rename to fail with "target already exists". Returning undoes.reverse() ensures inverse moves run in reverse order during undo (and restores original forward order upon redo).
In FileUndoRedoElement._reverse(), operations across different groups were also executed in forward order. Reversing this.operations ensures multi-group operations are undone in reverse order and redone in forward order.
Submitting a PR with this fix and regression tests shortly.
Ayush Kr Singh (@ayushkrsingh946) Thanks for looking into it. #344772 already fixes both, with regression tests in bulkFileEdits.test.ts, so a second PR isn't needed.
Activity
vs-code-engineering commentedon Oct 28, 2026
Thanks for creating this issue! It looks like you may be using an old version of VS Code; the latest stable release is 1.143.1. Please try upgrading to the latest version and checking whether this issue remains.
Happy Coding!
Undo the file operations of a workspace edit in reverse order
lagergren commentedon Oct 28, 2026
This is still the case on
main(915c6faed9c, 2026-10-28), which is newer than 1.143.1:FileUndoRedoElement._reverse()andRenameOperation.perform()inbulkFileEdits.tshaven't changed. #344772 fixes it.ayushkrsingh946 commentedon Oct 28, 2026
I investigated this issue and verified the root causes:
RenameOperation.perform(), inverse moves (undoes) were being returned in forward application order. When an edit moves a file out of a folder and then renames the folder, undoing in original order attempts to move the file back first (which creates the folder before the folder rename can occur), causing the folder rename to fail with "target already exists". Returningundoes.reverse()ensures inverse moves run in reverse order during undo (and restores original forward order upon redo).FileUndoRedoElement._reverse(), operations across different groups were also executed in forward order. Reversingthis.operationsensures multi-group operations are undone in reverse order and redone in forward order.Submitting a PR with this fix and regression tests shortly.
lagergren commentedon Oct 28, 2026
Ayush Kr Singh (@ayushkrsingh946) Thanks for looking into it. #344772 already fixes both, with regression tests in
bulkFileEdits.test.ts, so a second PR isn't needed.Record UP23's VS Code issue, microsoft/vscode#344765
Record UP23's VS Code issue, microsoft/vscode#344765
Record UP23's VS Code issue, microsoft/vscode#344765
Record UP23's VS Code issue, microsoft/vscode#344765
Record UP23's VS Code issue, microsoft/vscode#344765
Record UP23's VS Code issue, microsoft/vscode#344765
Record UP23's VS Code issue, microsoft/vscode#344765
Undo the file operations of a workspace edit in reverse order
Record UP23's VS Code issue, microsoft/vscode#344765
Record UP23's VS Code issue, microsoft/vscode#344765
Record UP23's VS Code issue, microsoft/vscode#344765
Record UP23's VS Code issue, microsoft/vscode#344765
Record UP23's VS Code issue, microsoft/vscode#344765
Record UP23's VS Code issue, microsoft/vscode#344765
Record UP23's VS Code issue, microsoft/vscode#344765
Record UP23's VS Code issue, microsoft/vscode#344765
Record UP23's VS Code issue, microsoft/vscode#344765
Record UP23's VS Code issue, microsoft/vscode#344765
Record UP23's VS Code issue, microsoft/vscode#344765
Record UP23's VS Code issue, microsoft/vscode#344765