本文整理汇总了TypeScript中vscode.WorkspaceEdit.insert方法的典型用法代码示例。如果您正苦于以下问题:TypeScript WorkspaceEdit.insert方法的具体用法?TypeScript WorkspaceEdit.insert怎么用?TypeScript WorkspaceEdit.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vscode.WorkspaceEdit
的用法示例。
在下文中一共展示了WorkspaceEdit.insert方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
saveText: async (text: string) => {
const filename = await utils.createFile('', getFixturePath([
rule,
value,
'test'
]));
const doc = await workspace.openTextDocument(filename);
await window.showTextDocument(doc);
const edit = new WorkspaceEdit();
edit.insert(doc.uri, new Position(0, 0), text);
assert.strictEqual(
await workspace.applyEdit(edit),
true,
'applies edit'
);
return await new Promise(resolve => {
let saveCount = 0;
workspace.onDidSaveTextDocument(savedDoc => {
if (++saveCount === (options.saves || 1)) {
resolve(savedDoc.getText());
}
});
doc.save();
});
}
示例2: applyUsingWorkspaceEdit
// Applies Edits to given WorkspaceEdit
applyUsingWorkspaceEdit(workspaceEdit: WorkspaceEdit, fileUri: Uri): void {
switch (this.action) {
case EditTypes.EDIT_INSERT:
workspaceEdit.insert(fileUri, this.start, this.text);
break;
case EditTypes.EDIT_DELETE:
workspaceEdit.delete(fileUri, new Range(this.start, this.end));
break;
case EditTypes.EDIT_REPLACE:
workspaceEdit.replace(fileUri, new Range(this.start, this.end), this.text);
break;
}
}
示例3: createDoc
return new Promise<string>(async resolve => {
const doc = await createDoc(options.contents);
workspace.onDidChangeTextDocument(doc.save);
workspace.onDidSaveTextDocument(savedDoc => {
assert.strictEqual(savedDoc.isDirty, false, 'dirty saved doc');
resolve(savedDoc.getText());
});
const edit = new WorkspaceEdit();
edit.insert(doc.uri, new Position(0, 0), text);
assert.strictEqual(
await workspace.applyEdit(edit),
true,
'editor fails to apply edit'
);
});
示例4: async
saveText: async (text: string) => {
const doc = await createDoc();
const edit = new WorkspaceEdit();
edit.insert(doc.uri, new Position(0, 0), text);
assert.strictEqual(
await workspace.applyEdit(edit),
true,
'applies edit'
);
return await new Promise(resolve => {
workspace.onDidSaveTextDocument(savedDoc => {
resolve(savedDoc.getText());
});
doc.save();
});
}
示例5: onDocumentOpen
function onDocumentOpen(td: TextDocument) {
let extension = extname(td.fileName);
if (extension != ".wurst" && extension != ".jurst") {
return;
}
if (td.lineCount > 1 || td.getText().length > 0) {
return;
}
let packageName = basename(td.fileName, extension);
let newText = `package ${packageName}\n\n`;
let edit = new WorkspaceEdit()
edit.insert(td.uri, new Position(1,1), newText)
workspace.applyEdit(edit);
}
示例6: addNewLine
public addNewLine(document: TextDocument) {
// get the line count
let lineCount = document.lineCount;
console.log('lineCount: ' + lineCount);
let allText = document.getText();
let matches = allText.match(/\r?\n$/);
if (matches) {
return;
}
let workspaceConfiguration = workspace.getConfiguration('editor');
let lineEnding: string = workspaceConfiguration.get<string>('lineEnding');
let uri = document.uri;
let workspaceEdit = new WorkspaceEdit();
let position = new Position(lineCount, 0);
workspaceEdit.insert(uri, position, lineEnding);
workspace.applyEdit(workspaceEdit).then(function() {
document.save();
});
}
示例7: test
test('jj -> <Esc> through modehandler', async () => {
const expectedDocumentContent = 'lorem ipsum';
// setup
await setupWithBindings({
insertModeKeyBindings: defaultInsertModeKeyBindings,
normalModeKeyBindings: defaultNormalModeKeyBindings,
visualModeKeyBindings: defaultVisualModeKeyBindings,
});
let remapper = new Remappers();
const edit = new vscode.WorkspaceEdit();
edit.insert(
vscode.window.activeTextEditor!.document.uri,
new vscode.Position(0, 0),
expectedDocumentContent
);
vscode.workspace.applyEdit(edit);
await modeHandler.handleKeyEvent('i');
assertEqual(modeHandler.currentMode.name, ModeName.Insert);
// act
let actual = false;
try {
actual = await remapper.sendKey(['j', 'j'], modeHandler, modeHandler.vimState);
} catch (e) {
assert.fail(e);
}
// assert
assert.equal(actual, true);
assertEqual(modeHandler.currentMode.name, ModeName.Normal);
assert.equal(vscode.window.activeTextEditor!.document.getText(), expectedDocumentContent);
});