applyEdit

Make changes to one or many resources or create, delete, and rename resources as defined by the given workspace edit.

All changes of a workspace edit are applied in the same order in which they have been added. If multiple textual inserts are made at the same position, these strings appear in the resulting text in the order the ‘inserts’ were made, unless that are interleaved with resource edits. Invalid sequences like ‘delete file a’ -> ‘insert text in file a’ cause failure of the operation.

When applying a workspace edit that consists only of text edits an ‘all-or-nothing’-strategy is used. A workspace edit with resource creations or deletions aborts the operation, e.g. consecutive edits will not be attempted, when a single edit fails.

Introduce

Parameter

Name Type Description
edit WorkspaceEdit A workspace edit.

Returns

Type Description
Promise<void> Promise

Example

  1. let editorPromise = hx.window.getActiveTextEditor();
  2. editorPromise.then((editor)=>{
  3. let workspaceEdit = new hx.WorkspaceEdit();
  4. let edits = [];
  5. edits.push(new hx.TextEdit({
  6. start: 0,
  7. end: 0
  8. }, "foo"));
  9. workspaceEdit.set(editor.document.uri,edits);
  10. hx.workspace.applyEdit(workspaceEdit);
  11. });

WorkspaceEdit

A workspace edit is a collection of textual and files changes for multiple resources and documents.

Use the applyEdit-function to apply a workspace edit.

set

Parameter

Name Type Description
uri String or Uri
edits Array<TextEdit> An array of text edits.

Returns

Type Description
Promise<void> Promise

Example

  1. let workspaceEdit = new hx.WorkspaceEdit();
  2. let edits = [];
  3. edits.push(new hx.TextEdit({
  4. start: 0,
  5. end: 0
  6. }, "foo"));
  7. workspaceEdit.set(doc.uri, edits);
  8. hx.workspace.applyEdit(workspaceEdit);

TextEdit

Attribute list

Attribute name Type Description
range Range The range this edit applies to.
newText String The string this edit will insert.

replace static

Parameter

Name Type Description
range Range A range.
newText String A string.

Returns

Type Description
TextEdit A new text edit object.

Range

A range represents an ordered pair of two positions. It is guaranteed that start.isBeforeOrEqual(end)

Attribute list

Attribute name Type Description
start Number The start position. It is before or equal to end.
end Number The end position. It is after or equal to start.