本文整理汇总了TypeScript中vscode.WorkspaceEdit类的典型用法代码示例。如果您正苦于以下问题:TypeScript WorkspaceEdit类的具体用法?TypeScript WorkspaceEdit怎么用?TypeScript WorkspaceEdit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WorkspaceEdit类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: setEditFactory
private setEditFactory(uri: Uri, coords, content): WorkspaceEdit {
var workspaceEdit = new WorkspaceEdit();
let edit = new TextEdit(coords, content);
workspaceEdit.set(uri, [edit]);
return workspaceEdit;
}
示例2: onCodeAction
private async onCodeAction(source: Source, workspaceEdit: WorkspaceEdit): Promise<boolean> {
const success = workspace.applyEdit(workspaceEdit);
if (!success) {
return false;
}
let firstEdit: TextEdit | undefined = undefined;
for (const [uri, edits] of workspaceEdit.entries()) {
if (uri.fsPath === source.uri.fsPath) {
firstEdit = edits[0];
break;
}
}
if (!firstEdit) {
return true;
}
const newLines = firstEdit.newText.match(/\n/g);
const editedRange = new Range(
firstEdit.range.start.line, 0,
firstEdit.range.end.line + 1 + (newLines ? newLines.length : 0), 0);
// TODO: Workaround for https://github.com/Microsoft/TypeScript/issues/12249
// apply formatting to the source range until TS returns formatted results
const edits = (await commands.executeCommand('vscode.executeFormatRangeProvider', source.uri, editedRange, source.formattingOptions || {})) as TextEdit[];
if (!edits || !edits.length) {
return false;
}
const formattingEdit = new WorkspaceEdit();
formattingEdit.set(source.uri, edits);
return workspace.applyEdit(formattingEdit);
}
示例3: applyCodeAction
export async function applyCodeAction(
client: ITypescriptServiceClient,
action: Proto.CodeAction,
file: string
): Promise<boolean> {
if (action.changes && action.changes.length) {
const workspaceEdit = new WorkspaceEdit();
for (const change of action.changes) {
for (const textChange of change.textChanges) {
workspaceEdit.replace(client.asUrl(change.fileName),
tsTextSpanToVsRange(textChange),
textChange.newText);
}
}
if (!(await workspace.applyEdit(workspaceEdit))) {
return false;
}
}
if (action.commands && action.commands.length) {
for (const command of action.commands) {
const response = await client.execute('applyCodeActionCommand', { file, command });
if (!response || !response.body) {
return false;
}
}
}
return true;
}
示例4: _revertChanges
private async _revertChanges(textEditor: TextEditor, changes: LineChange[]): Promise<void> {
const modifiedDocument = textEditor.document;
const modifiedUri = modifiedDocument.uri;
if (modifiedUri.scheme !== 'file') {
return;
}
const originalUri = toGitUri(modifiedUri, '~');
const originalDocument = await workspace.openTextDocument(originalUri);
const basename = path.basename(modifiedUri.fsPath);
const message = localize('confirm revert', "Are you sure you want to revert the selected changes in {0}?", basename);
const yes = localize('revert', "Revert Changes");
const pick = await window.showWarningMessage(message, { modal: true }, yes);
if (pick !== yes) {
return;
}
const result = applyLineChanges(originalDocument, modifiedDocument, changes);
const edit = new WorkspaceEdit();
edit.replace(modifiedUri, new Range(new Position(0, 0), modifiedDocument.lineAt(modifiedDocument.lineCount - 1).range.end), result);
workspace.applyEdit(edit);
await modifiedDocument.save();
}
示例5: 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();
});
}
示例6: WorkspaceEdit
return commands.executeCommand('vscode.executeFormatRangeProvider', source.uri, editedRange, source.formattingOptions || {}).then((edits: TextEdit[]) => {
if (!edits || !edits.length) {
return false;
}
const workspaceEdit = new WorkspaceEdit();
workspaceEdit.set(source.uri, edits);
return workspace.applyEdit(workspaceEdit);
});
示例7: applyTextEdit
function applyTextEdit(we) {
telemetry.traceEvent('command-applytextedit');
let wse = new vscode.WorkspaceEdit()
for (let edit of we.documentChanges[0].edits) {
wse.replace(we.documentChanges[0].textDocument.uri, new vscode.Range(edit.range.start.line, edit.range.start.character, edit.range.end.line, edit.range.end.character), edit.newText)
}
vscode.workspace.applyEdit(wse)
}
示例8: toWorkspaceEdit
private toWorkspaceEdit(edits: Proto.FileCodeEdits[]): WorkspaceEdit {
const workspaceEdit = new WorkspaceEdit();
for (const edit of edits) {
for (const textChange of edit.textChanges) {
workspaceEdit.replace(this.client.asUrl(edit.fileName),
tsTextSpanToVsRange(textChange),
textChange.newText);
}
}
return workspaceEdit;
}
示例9: onCodeAction
private async onCodeAction(action: Proto.CodeAction): Promise<boolean> {
const workspaceEdit = new WorkspaceEdit();
for (const change of action.changes) {
for (const textChange of change.textChanges) {
workspaceEdit.replace(this.client.asUrl(change.fileName),
tsTextSpanToVsRange(textChange),
textChange.newText);
}
}
return workspace.applyEdit(workspaceEdit);
}
示例10: toWorkspaceEdit
private toWorkspaceEdit(edits: Proto.FileCodeEdits[]): WorkspaceEdit {
const workspaceEdit = new WorkspaceEdit();
for (const edit of edits) {
for (const textChange of edit.textChanges) {
workspaceEdit.replace(this.client.asUrl(edit.fileName),
new Range(
textChange.start.line - 1, textChange.start.offset - 1,
textChange.end.line - 1, textChange.end.offset - 1),
textChange.newText);
}
}
return workspaceEdit;
}