MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / applyWorkspaceEdit

Function applyWorkspaceEdit

src/cm/lsp/codeActions.ts:199–244  ·  view source on GitHub ↗
(
	view: EditorView,
	edit: WorkspaceEdit,
)

Source from the content-addressed store, hash-verified

197}
198
199async 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:

Callers 1

applyCodeActionFunction · 0.85

Calls 2

applyChangesToFileFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected