We're trying to make edits to a file in our extension based on certain events, but we can't figure out how to actually apply the edits. We found: model.ts but we haven't been able to get it to work. If this is the correct API, can you please provide an example for how to use it.
If it's not right please point us in the right direction, and an example would be great. Thanks!
For Theia extensions:
https://github.com/theia-ide/theia/blob/ab28d1f4f4c6ff6875f57d46c173ca2bbb08a31b/packages/monaco/src/browser/monaco-workspace.ts#L258
For Theia plugins/VS Code extensions:
https://github.com/Microsoft/vscode/blob/b263184273c3753e84291caf0e5ee9a6752cf141/src/vs/vscode.d.ts#L7534
How would one get a WorkspaceEdit object?
For Theia extensions:
const workspaceEdit = {
[uri]: TextEdit.insert(position, 'Hello World!')
}
for VS Code extensions:
const workspaceEdit = new vscode.WorkspaceEdit();
workspaceEdit.insert(uri, position, 'Hello World!')
In order to get applyEdit to work, I had to use
const workspaceEdit = {
documentChanges: [{
textDocument: doc,
edits: [{
range: {
start: { line: i, character: i },
end: { line: i, character: i },
},
newText: 'text',
}]
}]
}