当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript WorkspaceEdit.replace方法代码示例

本文整理汇总了TypeScript中vscode.WorkspaceEdit.replace方法的典型用法代码示例。如果您正苦于以下问题:TypeScript WorkspaceEdit.replace方法的具体用法?TypeScript WorkspaceEdit.replace怎么用?TypeScript WorkspaceEdit.replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vscode.WorkspaceEdit的用法示例。


在下文中一共展示了WorkspaceEdit.replace方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: 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;
}
开发者ID:gokulakrishna9,项目名称:vscode,代码行数:30,代码来源:codeAction.ts

示例2: Range

			change.textChanges.forEach(textChange => {
				workspaceEdit.replace(this.client.asUrl(change.fileName),
					new Range(
						textChange.start.line - 1, textChange.start.offset - 1,
						textChange.end.line - 1, textChange.end.offset - 1),
					textChange.newText);
			});
开发者ID:diarmaidm,项目名称:vscode,代码行数:7,代码来源:codeActionProvider.ts

示例3: _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();
	}
开发者ID:golf1052,项目名称:vscode,代码行数:25,代码来源:commands.ts

示例4: provideRenameEdits

    provideRenameEdits(document: vs.TextDocument, position: vs.Position, newName: string, token: vs.CancellationToken): vs.WorkspaceEdit | Thenable<vs.WorkspaceEdit> {
        const found = findMatchingEnd(document.getText(), document.offsetAt(position), document.languageId !== 'xml');

        if (!found) {
            return undefined;
        }

        const edit = new vs.WorkspaceEdit();
        const startPos = found.start;
        edit.replace(document.uri, new vs.Range(document.positionAt(startPos), document.positionAt(startPos + found.length)), newName);

        const endPos = found.end;
        if (typeof endPos === 'number') {
            edit.replace(document.uri, new vs.Range(document.positionAt(endPos), document.positionAt(endPos + found.length)), newName);
        }

        return edit;
    }
开发者ID:krizzdewizz,项目名称:vscode-tag-rename,代码行数:18,代码来源:extension.ts

示例5: Range

					promise.then((document) =>
						workspaceEdit.replace(
							uri,
							new Range(
								document.positionAt(fileEdit.offset),
								document.positionAt(fileEdit.offset + fileEdit.length),
							),
							fileEdit.replacement,
						),
开发者ID:DanTup,项目名称:Dart-Code,代码行数:9,代码来源:dart_rename_provider.ts

示例6: 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)
}
开发者ID:JuliaEditorSupport,项目名称:julia-vscode,代码行数:9,代码来源:smallcommands.ts

示例7: 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;
	}
开发者ID:elibarzilay,项目名称:vscode,代码行数:11,代码来源:refactorProvider.ts

示例8: 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);
	}
开发者ID:elibarzilay,项目名称:vscode,代码行数:12,代码来源:codeActionProvider.ts

示例9: 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;
	}
开发者ID:Chan-PH,项目名称:vscode,代码行数:13,代码来源:refactorProvider.ts

示例10: createWorkspaceEditFromFileCodeEdits

export function createWorkspaceEditFromFileCodeEdits(
	client: ITypeScriptServiceClient,
	edits: Iterable<Proto.FileCodeEdits>
): vscode.WorkspaceEdit {
	const workspaceEdit = new vscode.WorkspaceEdit();
	for (const edit of edits) {
		for (const textChange of edit.textChanges) {
			workspaceEdit.replace(client.asUrl(edit.fileName),
				tsTextSpanToVsRange(textChange),
				textChange.newText);
		}
	}

	return workspaceEdit;
}
开发者ID:JarnoNijboer,项目名称:vscode,代码行数:15,代码来源:workspaceEdit.ts


注:本文中的vscode.WorkspaceEdit.replace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。