in server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/lspApplyWorkspaceEdit.ts [31:86]
public async invoke(params: LspApplyWorkspaceEditParams): Promise<InvokeOutput> {
try {
if (!params.edit || !params.edit.changes) {
return {
output: {
kind: 'text',
content: 'No valid workspace edit provided.',
},
}
}
// Count the number of edits to be applied
let totalEdits = 0
const documentUris = Object.keys(params.edit.changes)
for (const uri of documentUris) {
totalEdits += params.edit.changes[uri].length
}
if (totalEdits === 0) {
return {
output: {
kind: 'text',
content: 'No edits to apply.',
},
}
}
// Apply the workspace edit
const result = await this.lsp.workspace.applyWorkspaceEdit({ edit: params.edit })
if (result.applied) {
return {
output: {
kind: 'text',
content: `Successfully applied ${totalEdits} edit(s) to ${documentUris.length} document(s).`,
},
}
} else {
return {
output: {
kind: 'text',
content: `Failed to apply edits: ${result.failureReason || 'Unknown reason'}`,
},
}
}
} catch (error) {
this.logging.error(`Error applying workspace edit: ${error}`)
return {
output: {
kind: 'text',
content: `Error applying workspace edit: ${error}`,
},
}
}
}