( view: EditorView, edit: WorkspaceEdit, )
| 197 | } |
| 198 | |
| 199 | async function applyWorkspaceEdit( |
| 200 | view: EditorView, |
| 201 | edit: WorkspaceEdit, |
| 202 | ): Promise<boolean> { |
| 203 | const plugin = LSPPlugin.get(view); |
| 204 | if (!plugin) return false; |
| 205 | |
| 206 | const workspace = plugin.client.workspace as AcodeWorkspace; |
| 207 | if (!workspace) return false; |
| 208 | |
| 209 | let filesChanged = 0; |
| 210 | |
| 211 | const result = await plugin.client.withMapping(async (mapping) => { |
| 212 | // Handle simple changes format |
| 213 | if (edit.changes) { |
| 214 | for (const uri in edit.changes) { |
| 215 | const changes = edit.changes[uri] as LspChange[]; |
| 216 | if ( |
| 217 | changes.length && |
| 218 | (await applyChangesToFile(workspace, uri, changes, mapping)) |
| 219 | ) { |
| 220 | filesChanged++; |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | // Handle documentChanges format (supports versioned edits) |
| 226 | if (edit.documentChanges) { |
| 227 | for (const docChange of edit.documentChanges) { |
| 228 | if ("textDocument" in docChange && "edits" in docChange) { |
| 229 | const uri = docChange.textDocument.uri; |
| 230 | const edits = docChange.edits as LspChange[]; |
| 231 | if ( |
| 232 | edits.length && |
| 233 | (await applyChangesToFile(workspace, uri, edits, mapping)) |
| 234 | ) { |
| 235 | filesChanged++; |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | return filesChanged; |
| 241 | }); |
| 242 | |
| 243 | return (result ?? 0) > 0; |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Apply a code action following the LSP spec: |
no test coverage detected