Merge from vscode 777931080477e28b7c27e8f7d4b0d69897945946 (#9220)

This commit is contained in:
Anthony Dresser
2020-02-19 22:27:53 -08:00
committed by GitHub
parent ab6fb810f8
commit 0cec223301
115 changed files with 1431 additions and 1133 deletions

View File

@@ -12,10 +12,10 @@ import { DeleteOperations } from 'vs/editor/common/controller/cursorDeleteOperat
import { CursorChangeReason } from 'vs/editor/common/controller/cursorEvents';
import { TypeOperations, TypeWithAutoClosingCommand } from 'vs/editor/common/controller/cursorTypeOperations';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { Range, IRange } from 'vs/editor/common/core/range';
import { ISelection, Selection, SelectionDirection } from 'vs/editor/common/core/selection';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { IIdentifiedSingleEditOperation, ITextModel, TrackedRangeStickiness, IModelDeltaDecoration, ICursorStateComputer } from 'vs/editor/common/model';
import { ITextModel, TrackedRangeStickiness, IModelDeltaDecoration, ICursorStateComputer, IIdentifiedSingleEditOperation, IValidEditOperation } from 'vs/editor/common/model';
import { RawContentChangedType } from 'vs/editor/common/model/textModelEvents';
import * as viewEvents from 'vs/editor/common/view/viewEvents';
import { IViewModel } from 'vs/editor/common/viewModel/viewModel';
@@ -903,8 +903,8 @@ class CommandExecutor {
if (commandsData.hadTrackedEditOperation && filteredOperations.length > 0) {
filteredOperations[0]._isTracked = true;
}
let selectionsAfter = ctx.model.pushEditOperations(ctx.selectionsBefore, filteredOperations, (inverseEditOperations: IIdentifiedSingleEditOperation[]): Selection[] => {
let groupedInverseEditOperations: IIdentifiedSingleEditOperation[][] = [];
let selectionsAfter = ctx.model.pushEditOperations(ctx.selectionsBefore, filteredOperations, (inverseEditOperations: IValidEditOperation[]): Selection[] => {
let groupedInverseEditOperations: IValidEditOperation[][] = [];
for (let i = 0; i < ctx.selectionsBefore.length; i++) {
groupedInverseEditOperations[i] = [];
}
@@ -915,7 +915,7 @@ class CommandExecutor {
}
groupedInverseEditOperations[op.identifier.major].push(op);
}
const minorBasedSorter = (a: IIdentifiedSingleEditOperation, b: IIdentifiedSingleEditOperation) => {
const minorBasedSorter = (a: IValidEditOperation, b: IValidEditOperation) => {
return a.identifier!.minor - b.identifier!.minor;
};
let cursorSelections: Selection[] = [];
@@ -1000,8 +1000,8 @@ class CommandExecutor {
let operations: IIdentifiedSingleEditOperation[] = [];
let operationMinor = 0;
const addEditOperation = (selection: Range, text: string | null, forceMoveMarkers: boolean = false) => {
if (selection.isEmpty() && text === '') {
const addEditOperation = (range: IRange, text: string | null, forceMoveMarkers: boolean = false) => {
if (Range.isEmpty(range) && text === '') {
// This command wants to add a no-op => no thank you
return;
}
@@ -1010,7 +1010,7 @@ class CommandExecutor {
major: majorIdentifier,
minor: operationMinor++
},
range: selection,
range: range,
text: text,
forceMoveMarkers: forceMoveMarkers,
isAutoWhitespaceEdit: command.insertsAutoWhitespace
@@ -1018,12 +1018,13 @@ class CommandExecutor {
};
let hadTrackedEditOperation = false;
const addTrackedEditOperation = (selection: Range, text: string | null, forceMoveMarkers?: boolean) => {
const addTrackedEditOperation = (selection: IRange, text: string | null, forceMoveMarkers?: boolean) => {
hadTrackedEditOperation = true;
addEditOperation(selection, text, forceMoveMarkers);
};
const trackSelection = (selection: Selection, trackPreviousOnEmpty?: boolean) => {
const trackSelection = (_selection: ISelection, trackPreviousOnEmpty?: boolean) => {
const selection = Selection.liftSelection(_selection);
let stickiness: TrackedRangeStickiness;
if (selection.isEmpty()) {
if (typeof trackPreviousOnEmpty === 'boolean') {
@@ -1093,7 +1094,7 @@ class CommandExecutor {
const previousOp = operations[i - 1];
const currentOp = operations[i];
if (previousOp.range.getStartPosition().isBefore(currentOp.range.getEndPosition())) {
if (Range.getStartPosition(previousOp.range).isBefore(Range.getEndPosition(currentOp.range))) {
let loserMajor: number;

View File

@@ -264,14 +264,28 @@ export class Range {
* Return the end position (which will be after or equal to the start position)
*/
public getEndPosition(): Position {
return new Position(this.endLineNumber, this.endColumn);
return Range.getEndPosition(this);
}
/**
* Return the end position (which will be after or equal to the start position)
*/
public static getEndPosition(range: IRange): Position {
return new Position(range.endLineNumber, range.endColumn);
}
/**
* Return the start position (which will be before or equal to the end position)
*/
public getStartPosition(): Position {
return new Position(this.startLineNumber, this.startColumn);
return Range.getStartPosition(this);
}
/**
* Return the start position (which will be before or equal to the end position)
*/
public static getStartPosition(range: IRange): Position {
return new Position(range.startLineNumber, range.startColumn);
}
/**

View File

@@ -10,7 +10,7 @@ import { ConfigurationChangedEvent, IComputedEditorOptions, IEditorOptions } fro
import { IPosition, Position } from 'vs/editor/common/core/position';
import { IRange, Range } from 'vs/editor/common/core/range';
import { ISelection, Selection } from 'vs/editor/common/core/selection';
import { IIdentifiedSingleEditOperation, IModelDecorationsChangeAccessor, ITextModel, OverviewRulerLane, TrackedRangeStickiness } from 'vs/editor/common/model';
import { IModelDecorationsChangeAccessor, ITextModel, OverviewRulerLane, TrackedRangeStickiness, IValidEditOperation } from 'vs/editor/common/model';
import { ThemeColor } from 'vs/platform/theme/common/themeService';
/**
@@ -22,7 +22,7 @@ export interface IEditOperationBuilder {
* @param range The range to replace (delete). May be empty to represent a simple insert.
* @param text The text to replace with. May be null to represent a simple delete.
*/
addEditOperation(range: Range, text: string | null, forceMoveMarkers?: boolean): void;
addEditOperation(range: IRange, text: string | null, forceMoveMarkers?: boolean): void;
/**
* Add a new edit operation (a replace operation).
@@ -30,7 +30,7 @@ export interface IEditOperationBuilder {
* @param range The range to replace (delete). May be empty to represent a simple insert.
* @param text The text to replace with. May be null to represent a simple delete.
*/
addTrackedEditOperation(range: Range, text: string | null, forceMoveMarkers?: boolean): void;
addTrackedEditOperation(range: IRange, text: string | null, forceMoveMarkers?: boolean): void;
/**
* Track `selection` when applying edit operations.
@@ -51,7 +51,7 @@ export interface ICursorStateComputerData {
/**
* Get the inverse edit operations of the added edit operations.
*/
getInverseEditOperations(): IIdentifiedSingleEditOperation[];
getInverseEditOperations(): IValidEditOperation[];
/**
* Get a previously tracked selection.
* @param id The unique identifier returned by `trackSelection`.

View File

@@ -335,7 +335,7 @@ export interface IIdentifiedSingleEditOperation {
/**
* The range to replace. This can be empty to emulate a simple insert.
*/
range: Range;
range: IRange;
/**
* The text to replace with. This can be null to emulate a simple delete.
*/
@@ -358,6 +358,27 @@ export interface IIdentifiedSingleEditOperation {
_isTracked?: boolean;
}
export interface IValidEditOperation {
/**
* An identifier associated with this single edit operation.
* @internal
*/
identifier: ISingleEditOperationIdentifier | null;
/**
* The range to replace. This can be empty to emulate a simple insert.
*/
range: Range;
/**
* The text to replace with. This can be null to emulate a simple delete.
*/
text: string | null;
/**
* This indicates that this operation has "insert" semantics.
* i.e. forceMoveMarkers = true => if `range` is collapsed, all markers at the position will be moved.
*/
forceMoveMarkers: boolean;
}
/**
* A callback that can compute the cursor state after applying a series of edit operations.
*/
@@ -365,7 +386,7 @@ export interface ICursorStateComputer {
/**
* A callback that can compute the resulting cursors state after some edit operations have been executed.
*/
(inverseEditOperations: IIdentifiedSingleEditOperation[]): Selection[] | null;
(inverseEditOperations: IValidEditOperation[]): Selection[] | null;
}
export class TextModelResolvedOptions {
@@ -1063,7 +1084,7 @@ export interface ITextModel {
* @param operations The edit operations.
* @return The inverse edit operations, that, when applied, will bring the model back to the previous state.
*/
applyEdits(operations: IIdentifiedSingleEditOperation[]): IIdentifiedSingleEditOperation[];
applyEdits(operations: IIdentifiedSingleEditOperation[]): IValidEditOperation[];
/**
* Change the end of line sequence without recording in the undo stack.
@@ -1206,6 +1227,20 @@ export const enum ModelConstants {
FIRST_LINE_DETECTION_LENGTH_LIMIT = 1000
}
/**
* @internal
*/
export class ValidAnnotatedEditOperation implements IIdentifiedSingleEditOperation {
constructor(
public readonly identifier: ISingleEditOperationIdentifier | null,
public readonly range: Range,
public readonly text: string | null,
public readonly forceMoveMarkers: boolean,
public readonly isAutoWhitespaceEdit: boolean,
public readonly _isTracked: boolean,
) { }
}
/**
* @internal
*/
@@ -1234,7 +1269,7 @@ export interface ITextBuffer {
getLineLastNonWhitespaceColumn(lineNumber: number): number;
setEOL(newEOL: '\r\n' | '\n'): void;
applyEdits(rawOperations: IIdentifiedSingleEditOperation[], recordTrimAutoWhitespace: boolean): ApplyEditsResult;
applyEdits(rawOperations: ValidAnnotatedEditOperation[], recordTrimAutoWhitespace: boolean): ApplyEditsResult;
findMatchesLineByLine(searchRange: Range, searchData: SearchData, captureMatches: boolean, limitResultCount: number): FindMatch[];
}
@@ -1244,7 +1279,7 @@ export interface ITextBuffer {
export class ApplyEditsResult {
constructor(
public readonly reverseEdits: IIdentifiedSingleEditOperation[],
public readonly reverseEdits: IValidEditOperation[],
public readonly changes: IInternalModelContentChange[],
public readonly trimAutoWhitespaceLineNumbers: number[] | null
) { }

View File

@@ -5,11 +5,11 @@
import { onUnexpectedError } from 'vs/base/common/errors';
import { Selection } from 'vs/editor/common/core/selection';
import { EndOfLineSequence, ICursorStateComputer, IIdentifiedSingleEditOperation } from 'vs/editor/common/model';
import { EndOfLineSequence, ICursorStateComputer, IIdentifiedSingleEditOperation, IValidEditOperation } from 'vs/editor/common/model';
import { TextModel } from 'vs/editor/common/model/textModel';
interface IEditOperation {
operations: IIdentifiedSingleEditOperation[];
operations: IValidEditOperation[];
}
interface IStackElement {
@@ -174,7 +174,7 @@ export class EditStack {
return stackElement!.afterCursorState;
}
private static _computeCursorState(cursorStateComputer: ICursorStateComputer | null, inverseEditOperations: IIdentifiedSingleEditOperation[]): Selection[] | null {
private static _computeCursorState(cursorStateComputer: ICursorStateComputer | null, inverseEditOperations: IValidEditOperation[]): Selection[] | null {
try {
return cursorStateComputer ? cursorStateComputer(inverseEditOperations) : null;
} catch (e) {

View File

@@ -6,7 +6,7 @@
import * as strings from 'vs/base/common/strings';
import { Position } from 'vs/editor/common/core/position';
import { Range } from 'vs/editor/common/core/range';
import { ApplyEditsResult, EndOfLinePreference, FindMatch, IIdentifiedSingleEditOperation, IInternalModelContentChange, ISingleEditOperationIdentifier, ITextBuffer, ITextSnapshot } from 'vs/editor/common/model';
import { ApplyEditsResult, EndOfLinePreference, FindMatch, IInternalModelContentChange, ISingleEditOperationIdentifier, ITextBuffer, ITextSnapshot, ValidAnnotatedEditOperation, IValidEditOperation } from 'vs/editor/common/model';
import { PieceTreeBase, StringBuffer } from 'vs/editor/common/model/pieceTreeTextBuffer/pieceTreeBase';
import { SearchData } from 'vs/editor/common/model/textModelSearch';
@@ -21,7 +21,7 @@ export interface IValidatedEditOperation {
isAutoWhitespaceEdit: boolean;
}
export interface IReverseSingleEditOperation extends IIdentifiedSingleEditOperation {
export interface IReverseSingleEditOperation extends IValidEditOperation {
sortIndex: number;
}
@@ -201,7 +201,7 @@ export class PieceTreeTextBuffer implements ITextBuffer {
this._pieceTree.setEOL(newEOL);
}
public applyEdits(rawOperations: IIdentifiedSingleEditOperation[], recordTrimAutoWhitespace: boolean): ApplyEditsResult {
public applyEdits(rawOperations: ValidAnnotatedEditOperation[], recordTrimAutoWhitespace: boolean): ApplyEditsResult {
let mightContainRTL = this._mightContainRTL;
let mightContainNonBasicASCII = this._mightContainNonBasicASCII;
let canReduceOperations = true;

View File

@@ -1154,18 +1154,40 @@ export class TextModel extends Disposable implements model.ITextModel {
}
}
private _validateEditOperation(rawOperation: model.IIdentifiedSingleEditOperation): model.ValidAnnotatedEditOperation {
if (rawOperation instanceof model.ValidAnnotatedEditOperation) {
return rawOperation;
}
return new model.ValidAnnotatedEditOperation(
rawOperation.identifier || null,
this.validateRange(rawOperation.range),
rawOperation.text,
rawOperation.forceMoveMarkers || false,
rawOperation.isAutoWhitespaceEdit || false,
rawOperation._isTracked || false
);
}
private _validateEditOperations(rawOperations: model.IIdentifiedSingleEditOperation[]): model.ValidAnnotatedEditOperation[] {
const result: model.ValidAnnotatedEditOperation[] = [];
for (let i = 0, len = rawOperations.length; i < len; i++) {
result[i] = this._validateEditOperation(rawOperations[i]);
}
return result;
}
public pushEditOperations(beforeCursorState: Selection[], editOperations: model.IIdentifiedSingleEditOperation[], cursorStateComputer: model.ICursorStateComputer | null): Selection[] | null {
try {
this._onDidChangeDecorations.beginDeferredEmit();
this._eventEmitter.beginDeferredEmit();
return this._pushEditOperations(beforeCursorState, editOperations, cursorStateComputer);
return this._pushEditOperations(beforeCursorState, this._validateEditOperations(editOperations), cursorStateComputer);
} finally {
this._eventEmitter.endDeferredEmit();
this._onDidChangeDecorations.endDeferredEmit();
}
}
private _pushEditOperations(beforeCursorState: Selection[], editOperations: model.IIdentifiedSingleEditOperation[], cursorStateComputer: model.ICursorStateComputer | null): Selection[] | null {
private _pushEditOperations(beforeCursorState: Selection[], editOperations: model.ValidAnnotatedEditOperation[], cursorStateComputer: model.ICursorStateComputer | null): Selection[] | null {
if (this._options.trimAutoWhitespace && this._trimAutoWhitespaceLines) {
// Go through each saved line number and insert a trim whitespace edit
// if it is safe to do so (no conflicts with other edits).
@@ -1238,10 +1260,8 @@ export class TextModel extends Disposable implements model.ITextModel {
}
if (allowTrimLine) {
editOperations.push({
range: new Range(trimLineNumber, 1, trimLineNumber, maxLineColumn),
text: null
});
const trimRange = new Range(trimLineNumber, 1, trimLineNumber, maxLineColumn);
editOperations.push(new model.ValidAnnotatedEditOperation(null, trimRange, null, false, false, false));
}
}
@@ -1252,21 +1272,18 @@ export class TextModel extends Disposable implements model.ITextModel {
return this._commandManager.pushEditOperation(beforeCursorState, editOperations, cursorStateComputer);
}
public applyEdits(rawOperations: model.IIdentifiedSingleEditOperation[]): model.IIdentifiedSingleEditOperation[] {
public applyEdits(rawOperations: model.IIdentifiedSingleEditOperation[]): model.IValidEditOperation[] {
try {
this._onDidChangeDecorations.beginDeferredEmit();
this._eventEmitter.beginDeferredEmit();
return this._applyEdits(rawOperations);
return this._applyEdits(this._validateEditOperations(rawOperations));
} finally {
this._eventEmitter.endDeferredEmit();
this._onDidChangeDecorations.endDeferredEmit();
}
}
private _applyEdits(rawOperations: model.IIdentifiedSingleEditOperation[]): model.IIdentifiedSingleEditOperation[] {
for (let i = 0, len = rawOperations.length; i < len; i++) {
rawOperations[i].range = this.validateRange(rawOperations[i].range);
}
private _applyEdits(rawOperations: model.ValidAnnotatedEditOperation[]): model.IValidEditOperation[] {
const oldLineCount = this._buffer.getLineCount();
const result = this._buffer.applyEdits(rawOperations, this._options.trimAutoWhitespace);

View File

@@ -1324,7 +1324,7 @@ export interface WorkspaceEditMetadata {
needsConfirmation: boolean;
label: string;
description?: string;
iconPath?: { id: string } | { light: URI, dark: URI };
iconPath?: { id: string } | URI | { light: URI, dark: URI };
}
export interface WorkspaceFileEditOptions {

View File

@@ -11,7 +11,7 @@ import { URI } from 'vs/base/common/uri';
import { EDITOR_MODEL_DEFAULTS } from 'vs/editor/common/config/editorOptions';
import { EditOperation } from 'vs/editor/common/core/editOperation';
import { Range } from 'vs/editor/common/core/range';
import { DefaultEndOfLine, EndOfLinePreference, EndOfLineSequence, IIdentifiedSingleEditOperation, ITextBuffer, ITextBufferFactory, ITextModel, ITextModelCreationOptions } from 'vs/editor/common/model';
import { DefaultEndOfLine, EndOfLinePreference, EndOfLineSequence, IIdentifiedSingleEditOperation, ITextBuffer, ITextBufferFactory, ITextModel, ITextModelCreationOptions, IValidEditOperation } from 'vs/editor/common/model';
import { TextModel, createTextBuffer } from 'vs/editor/common/model/textModel';
import { IModelLanguageChangedEvent, IModelContentChangedEvent } from 'vs/editor/common/model/textModelEvents';
import { LanguageIdentifier, DocumentSemanticTokensProviderRegistry, DocumentSemanticTokensProvider, SemanticTokensLegend, SemanticTokens, SemanticTokensEdits, TokenMetadata, FontStyle, MetadataConsts } from 'vs/editor/common/modes';
@@ -305,7 +305,7 @@ export class ModelServiceImpl extends Disposable implements IModelService {
model.pushEditOperations(
[],
ModelServiceImpl._computeEdits(model, textBuffer),
(inverseEditOperations: IIdentifiedSingleEditOperation[]) => []
(inverseEditOperations: IValidEditOperation[]) => []
);
model.pushStackElement();
}