(query: any[], id: string | null = null)
| 117 | } |
| 118 | |
| 119 | export async function insertOrModifyText(query: any[], id: string | null = null) { |
| 120 | |
| 121 | |
| 122 | const target = findTargetUri(id); |
| 123 | const targetDocument = await workspace.openTextDocument(target); |
| 124 | console.info(`[insertTextAtPosition] inserting text into: ${target.path}`); |
| 125 | const edit = new WorkspaceEdit(); |
| 126 | |
| 127 | query.forEach((op) => { |
| 128 | assertSupportedEditOperation(op.operation); |
| 129 | |
| 130 | let editLocation: any; |
| 131 | const editText = normaliseEditText(op.text, op.location, op.operation, targetDocument); |
| 132 | |
| 133 | if (op.operation === 'insertText') { |
| 134 | editLocation = parsePosition(op.location, targetDocument); |
| 135 | console.info(`[insertTextAtPosition] inserting at: ${JSON.stringify(editLocation)}`); |
| 136 | console.info(`[insertTextAtPosition] inserting text: ${editText}`); |
| 137 | edit.insert(target, editLocation, editText); |
| 138 | } else { |
| 139 | editLocation = parseRange(op.location, targetDocument); |
| 140 | console.info(`[insertTextAtPosition] replacing at: ${JSON.stringify(editLocation)}`); |
| 141 | console.info(`[insertTextAtPosition] replacing with text: ${editText}`); |
| 142 | edit.replace(target, editLocation, editText); |
| 143 | } |
| 144 | }); |
| 145 | |
| 146 | void workspace.applyEdit(edit); |
| 147 | } |
| 148 | |
| 149 | export async function replaceTextInCurrentSelection(text: string, id: string): Promise<void> { |
| 150 | const target = findTargetUri(id); |
no test coverage detected