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

vinokurig picture vinokurig  路  3Comments

kpge picture kpge  路  3Comments

jeanlucburot picture jeanlucburot  路  3Comments

akosyakov picture akosyakov  路  3Comments

vince-fugnitto picture vince-fugnitto  路  3Comments