Theia: Make edits to a file from an extension?

Created on 8 Mar 2019  路  4Comments  路  Source: eclipse-theia/theia

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!

question

All 4 comments

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',
    }]
  }]
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

kittaakos picture kittaakos  路  22Comments

tolusha picture tolusha  路  22Comments

lmcbout picture lmcbout  路  29Comments

adrienrenaud picture adrienrenaud  路  22Comments

lmcbout picture lmcbout  路  22Comments