提交 7b1da3a3 编写于 作者: J Johannes Rieken
上级 92729027
......@@ -11,6 +11,7 @@ import { IDisposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { isObject } from 'vs/base/common/types';
import { UndoRedoSource } from 'vs/platform/undoRedo/common/undoRedo';
import { CancellationToken } from 'vs/base/common/cancellation';
export const IBulkEditService = createDecorator<IBulkEditService>('IWorkspaceEditService');
......@@ -66,6 +67,7 @@ export class ResourceFileEdit extends ResourceEdit {
export interface IBulkEditOptions {
editor?: ICodeEditor;
progress?: IProgress<IProgressStep>;
token?: CancellationToken;
showPreview?: boolean;
label?: string;
quotableLabel?: string;
......
......@@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { groupBy } from 'vs/base/common/arrays';
import { CancellationToken } from 'vs/base/common/cancellation';
import { compare } from 'vs/base/common/strings';
import { URI } from 'vs/base/common/uri';
import { ResourceEdit } from 'vs/editor/browser/services/bulkEditService';
......@@ -31,6 +32,7 @@ export class BulkCellEdits {
private readonly _undoRedoGroup: UndoRedoGroup,
undoRedoSource: UndoRedoSource | undefined,
private readonly _progress: IProgress<void>,
private readonly _token: CancellationToken,
private readonly _edits: ResourceNotebookCellEdit[],
@INotebookEditorModelResolverService private readonly _notebookModelService: INotebookEditorModelResolverService,
) { }
......@@ -40,6 +42,9 @@ export class BulkCellEdits {
const editsByNotebook = groupBy(this._edits, (a, b) => compare(a.resource.toString(), b.resource.toString()));
for (let group of editsByNotebook) {
if (this._token.isCancellationRequested) {
break;
}
const [first] = group;
const ref = await this._notebookModelService.resolve(first.resource);
......
......@@ -18,6 +18,7 @@ import { BulkFileEdits } from 'vs/workbench/contrib/bulkEdit/browser/bulkFileEdi
import { BulkCellEdits, ResourceNotebookCellEdit } from 'vs/workbench/contrib/bulkEdit/browser/bulkCellEdits';
import { UndoRedoGroup, UndoRedoSource } from 'vs/platform/undoRedo/common/undoRedo';
import { LinkedList } from 'vs/base/common/linkedList';
import { CancellationToken } from 'vs/base/common/cancellation';
class BulkEdit {
......@@ -25,6 +26,7 @@ class BulkEdit {
private readonly _label: string | undefined,
private readonly _editor: ICodeEditor | undefined,
private readonly _progress: IProgress<IProgressStep>,
private readonly _token: CancellationToken,
private readonly _edits: ResourceEdit[],
private readonly _undoRedoGroup: UndoRedoGroup,
private readonly _undoRedoSource: UndoRedoSource | undefined,
......@@ -82,19 +84,19 @@ class BulkEdit {
private async _performFileEdits(edits: ResourceFileEdit[], undoRedoGroup: UndoRedoGroup, undoRedoSource: UndoRedoSource | undefined, progress: IProgress<void>) {
this._logService.debug('_performFileEdits', JSON.stringify(edits));
const model = this._instaService.createInstance(BulkFileEdits, this._label || localize('workspaceEdit', "Workspace Edit"), undoRedoGroup, undoRedoSource, progress, edits);
const model = this._instaService.createInstance(BulkFileEdits, this._label || localize('workspaceEdit', "Workspace Edit"), undoRedoGroup, undoRedoSource, progress, this._token, edits);
await model.apply();
}
private async _performTextEdits(edits: ResourceTextEdit[], undoRedoGroup: UndoRedoGroup, undoRedoSource: UndoRedoSource | undefined, progress: IProgress<void>): Promise<void> {
this._logService.debug('_performTextEdits', JSON.stringify(edits));
const model = this._instaService.createInstance(BulkTextEdits, this._label || localize('workspaceEdit', "Workspace Edit"), this._editor, undoRedoGroup, undoRedoSource, progress, edits);
const model = this._instaService.createInstance(BulkTextEdits, this._label || localize('workspaceEdit', "Workspace Edit"), this._editor, undoRedoGroup, undoRedoSource, progress, this._token, edits);
await model.apply();
}
private async _performCellEdits(edits: ResourceNotebookCellEdit[], undoRedoGroup: UndoRedoGroup, undoRedoSource: UndoRedoSource | undefined, progress: IProgress<void>): Promise<void> {
this._logService.debug('_performCellEdits', JSON.stringify(edits));
const model = this._instaService.createInstance(BulkCellEdits, undoRedoGroup, undoRedoSource, progress, edits);
const model = this._instaService.createInstance(BulkCellEdits, undoRedoGroup, undoRedoSource, progress, this._token, edits);
await model.apply();
}
}
......@@ -170,7 +172,9 @@ export class BulkEditService implements IBulkEditService {
const bulkEdit = this._instaService.createInstance(
BulkEdit,
options?.quotableLabel || options?.label,
codeEditor, options?.progress ?? Progress.None,
codeEditor,
options?.progress ?? Progress.None,
options?.token ?? CancellationToken.None,
edits,
undoRedoGroup,
options?.undoRedoSource
......
......@@ -16,6 +16,7 @@ import { ILogService } from 'vs/platform/log/common/log';
import { VSBuffer } from 'vs/base/common/buffer';
import { ResourceFileEdit } from 'vs/editor/browser/services/bulkEditService';
import * as resources from 'vs/base/common/resources';
import { CancellationToken } from 'vs/base/common/cancellation';
interface IFileOperationUndoRedoInfo {
undoRedoGroupId?: number;
......@@ -227,6 +228,7 @@ export class BulkFileEdits {
private readonly _undoRedoGroup: UndoRedoGroup,
private readonly _undoRedoSource: UndoRedoSource | undefined,
private readonly _progress: IProgress<void>,
private readonly _token: CancellationToken,
private readonly _edits: ResourceFileEdit[],
@IInstantiationService private readonly _instaService: IInstantiationService,
@IUndoRedoService private readonly _undoRedoService: IUndoRedoService,
......@@ -236,6 +238,11 @@ export class BulkFileEdits {
const undoOperations: IFileOperation[] = [];
const undoRedoInfo = { undoRedoGroupId: this._undoRedoGroup.id };
for (const edit of this._edits) {
if (this._token.isCancellationRequested) {
break;
}
this._progress.report(undefined);
const options = edit.options || {};
......
......@@ -19,6 +19,7 @@ import { SingleModelEditStackElement, MultiModelEditStackElement } from 'vs/edit
import { ResourceMap } from 'vs/base/common/map';
import { IModelService } from 'vs/editor/common/services/modelService';
import { ResourceTextEdit } from 'vs/editor/browser/services/bulkEditService';
import { CancellationToken } from 'vs/base/common/cancellation';
type ValidationResult = { canApply: true } | { canApply: false, reason: URI };
......@@ -136,6 +137,7 @@ export class BulkTextEdits {
private readonly _undoRedoGroup: UndoRedoGroup,
private readonly _undoRedoSource: UndoRedoSource | undefined,
private readonly _progress: IProgress<void>,
private readonly _token: CancellationToken,
edits: ResourceTextEdit[],
@IEditorWorkerService private readonly _editorWorker: IEditorWorkerService,
@IModelService private readonly _modelService: IModelService,
......@@ -223,6 +225,9 @@ export class BulkTextEdits {
this._validateBeforePrepare();
const tasks = await this._createEditsTasks();
if (this._token.isCancellationRequested) {
return;
}
try {
const validation = this._validateTasks(tasks);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册