Merge from vscode 33a65245075e4d18908652865a79cf5489c30f40 (#9279)

* Merge from vscode 33a65245075e4d18908652865a79cf5489c30f40

* remove github
This commit is contained in:
Anthony Dresser
2020-02-21 23:42:19 -08:00
committed by GitHub
parent c446cea3a0
commit de5f1eb780
250 changed files with 3724 additions and 2756 deletions

View File

@@ -10,6 +10,7 @@ import { ICodeEditor, isCodeEditor } from 'vs/editor/browser/editorBrowser';
import { IBulkEditOptions, IBulkEditResult, IBulkEditService, IBulkEditPreviewHandler } from 'vs/editor/browser/services/bulkEditService';
import { EditOperation } from 'vs/editor/common/core/editOperation';
import { Range } from 'vs/editor/common/core/range';
import { Selection } from 'vs/editor/common/core/selection';
import { EndOfLineSequence, IIdentifiedSingleEditOperation, ITextModel } from 'vs/editor/common/model';
import { WorkspaceFileEdit, WorkspaceTextEdit, WorkspaceEdit } from 'vs/editor/common/modes';
import { IModelService } from 'vs/editor/common/services/modelService';
@@ -18,7 +19,7 @@ import { localize } from 'vs/nls';
import { IFileService, FileSystemProviderCapabilities } from 'vs/platform/files/common/files';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { ILogService } from 'vs/platform/log/common/log';
import { IProgress, IProgressStep, emptyProgress } from 'vs/platform/progress/common/progress';
import { IProgress, IProgressStep, Progress } from 'vs/platform/progress/common/progress';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
@@ -26,20 +27,21 @@ import { EditorOption } from 'vs/editor/common/config/editorOptions';
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IWorkingCopyFileService } from 'vs/workbench/services/workingCopy/common/workingCopyFileService';
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
import { EditStackElement, MultiModelEditStackElement } from 'vs/editor/common/model/editStack';
type ValidationResult = { canApply: true } | { canApply: false, reason: URI };
class ModelEditTask implements IDisposable {
private readonly _model: ITextModel;
public readonly model: ITextModel;
protected _edits: IIdentifiedSingleEditOperation[];
private _expectedModelVersionId: number | undefined;
protected _newEol: EndOfLineSequence | undefined;
constructor(private readonly _modelReference: IReference<IResolvedTextEditorModel>) {
this._model = this._modelReference.object.textEditorModel;
this.model = this._modelReference.object.textEditorModel;
this._edits = [];
}
@@ -67,7 +69,7 @@ class ModelEditTask implements IDisposable {
// create edit operation
let range: Range;
if (!edit.range) {
range = this._model.getFullModelRange();
range = this.model.getFullModelRange();
} else {
range = Range.lift(edit.range);
}
@@ -75,23 +77,23 @@ class ModelEditTask implements IDisposable {
}
validate(): ValidationResult {
if (typeof this._expectedModelVersionId === 'undefined' || this._model.getVersionId() === this._expectedModelVersionId) {
if (typeof this._expectedModelVersionId === 'undefined' || this.model.getVersionId() === this._expectedModelVersionId) {
return { canApply: true };
}
return { canApply: false, reason: this._model.uri };
return { canApply: false, reason: this.model.uri };
}
getBeforeCursorState(): Selection[] | null {
return null;
}
apply(): void {
if (this._edits.length > 0) {
this._edits = mergeSort(this._edits, (a, b) => Range.compareRangesUsingStarts(a.range, b.range));
this._model.pushStackElement();
this._model.pushEditOperations([], this._edits, () => []);
this._model.pushStackElement();
this.model.pushEditOperations(null, this._edits, () => null);
}
if (this._newEol !== undefined) {
this._model.pushStackElement();
this._model.pushEOL(this._newEol);
this._model.pushStackElement();
this.model.pushEOL(this._newEol);
}
}
}
@@ -105,18 +107,18 @@ class EditorEditTask extends ModelEditTask {
this._editor = editor;
}
getBeforeCursorState(): Selection[] | null {
return this._editor.getSelections();
}
apply(): void {
if (this._edits.length > 0) {
this._edits = mergeSort(this._edits, (a, b) => Range.compareRangesUsingStarts(a.range, b.range));
this._editor.pushUndoStop();
this._editor.executeEdits('', this._edits);
this._editor.pushUndoStop();
}
if (this._newEol !== undefined) {
if (this._editor.hasModel()) {
this._editor.pushUndoStop();
this._editor.getModel().pushEOL(this._newEol);
this._editor.pushUndoStop();
}
}
}
@@ -133,6 +135,7 @@ class BulkEditModel implements IDisposable {
edits: WorkspaceTextEdit[],
@IEditorWorkerService private readonly _editorWorker: IEditorWorkerService,
@ITextModelService private readonly _textModelResolverService: ITextModelService,
@IUndoRedoService private readonly _undoRedoService: IUndoRedoService
) {
edits.forEach(this._addEdit, this);
}
@@ -215,10 +218,31 @@ class BulkEditModel implements IDisposable {
}
apply(): void {
for (const task of this._tasks!) {
const tasks = this._tasks!;
if (tasks.length === 1) {
// This edit touches a single model => keep things simple
for (const task of tasks) {
task.model.pushStackElement();
task.apply();
task.model.pushStackElement();
this._progress.report(undefined);
}
return;
}
const multiModelEditStackElement = new MultiModelEditStackElement(
localize('workspaceEdit', "Workspace Edit"),
tasks.map(t => new EditStackElement(t.model, t.getBeforeCursorState()))
);
this._undoRedoService.pushElement(multiModelEditStackElement);
for (const task of tasks) {
task.apply();
this._progress.report(undefined);
}
multiModelEditStackElement.close();
}
}
@@ -242,7 +266,7 @@ class BulkEdit {
@IConfigurationService private readonly _configurationService: IConfigurationService
) {
this._editor = editor;
this._progress = progress || emptyProgress;
this._progress = progress || Progress.None;
this._edits = edits;
}