applyEdit

根据指定的WorkspaceEdit对象编辑文档。WorkspaceEdit对象内要设定被修改文档的uri和要执行修改的TextEdit操作对象。

applyEdit介绍

参数说明

参数名称 参数类型 描述
edit WorkspaceEdit 文档编辑操作

返回值

返回类型 描述
Promise<void> Promise

示例

  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

WorkspaceEdit: 工作空间的一组编辑操作

set

参数说明

参数名称 参数类型 描述
uri String或Uri 文档地址
edits Array<TextEdit> 编辑操作数组

返回值

返回类型 描述
Promise<void> Promise

示例

  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

TextEdit: 文档编辑

属性列表

属性名 属性类型 描述
range Range 要修改的区域
newText String 要插入的新内容

replace static

参数说明

参数名称 参数类型 描述
range Range 要修改的区域
newText String 要插入的新内容

返回值

返回类型 描述
TextEdit 文档编辑对象

Range

Range: 文本区域

属性列表

属性名 属性类型 描述
start Number 起始位置
end Number 结束位置