Apply Workspace Edit
API Reference
Apply Workspace Edit
Apply text edits to files in your workspace
POST
Apply Workspace Edit
Overview
Apply text changes to one or more files in your workspace. This is used to execute the edits returned by other tools like rename, format, or code actions.Request
object
required
Workspace edit containing all changes
string
Optional description of the edit (e.g., “Rename variable”)
Response
boolean
Whether the edit was successfully applied
string
Error message if
applied is falsenumber
Number of files that were changed
number
Total number of text edits applied
Example Request
Example Response
Use Cases
Apply Rename Edits
Apply Format Changes
Apply Code Action
Batch Multiple Edits
Edit Application Order
Edits are applied in a specific order to prevent conflicts:1
Sort by File
Group edits by file URI
2
Sort by Position
Within each file, sort edits from bottom to top (descending line/character)
3
Apply Edits
Apply each edit, preventing line number shifts
4
Verify
Confirm all edits applied successfully
Bottom-to-top ordering ensures that edits don’t affect the positions of subsequent edits.
Error Handling
The operation is atomic - either all edits succeed or none are applied:Safety Features
Atomic Operation
All files updated together or none at all
Conflict Detection
Overlapping edits are rejected
Validation
File paths and ranges validated before applying
Rollback Support
Failed edits don’t leave partial changes
Best Practices
Preview First: Show user what will change before applying
Use Version Control: Commit before large edits so you can revert
Validate Ranges: Ensure all ranges are valid before applying
Add Labels: Always provide descriptive labels for better UX
Performance Tips
Error Responses
Rollback
If you need to undo an edit:Rate Limits
Related Tools
Rename Symbol
Generate rename edits to apply
Format Document
Generate format edits to apply
Get Code Actions
Get quick fix edits to apply
Get Diagnostics
Verify no errors after applying