Merge from master

This commit is contained in:
Raj Musuku
2019-02-21 17:56:04 -08:00
parent 5a146e34fa
commit 666ae11639
11482 changed files with 119352 additions and 255574 deletions

View File

@@ -3,45 +3,43 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import 'vs/css!./media/diffEditor';
import * as nls from 'vs/nls';
import { RunOnceScheduler } from 'vs/base/common/async';
import { Disposable } from 'vs/base/common/lifecycle';
import * as objects from 'vs/base/common/objects';
import * as dom from 'vs/base/browser/dom';
import { FastDomNode, createFastDomNode } from 'vs/base/browser/fastDomNode';
import { ISashEvent, IVerticalSashLayoutProvider, Sash, SashState } from 'vs/base/browser/ui/sash/sash';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { Range, IRange } from 'vs/editor/common/core/range';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
import { LineDecoration } from 'vs/editor/common/viewLayout/lineDecorations';
import { renderViewLine, RenderLineInput } from 'vs/editor/common/viewLayout/viewLineRenderer';
import * as editorBrowser from 'vs/editor/browser/editorBrowser';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { Configuration } from 'vs/editor/browser/config/configuration';
import { Position, IPosition } from 'vs/editor/common/core/position';
import { Selection, ISelection } from 'vs/editor/common/core/selection';
import { InlineDecoration, InlineDecorationType, ViewLineRenderingData } from 'vs/editor/common/viewModel/viewModel';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { Event, Emitter } from 'vs/base/common/event';
import * as editorOptions from 'vs/editor/common/config/editorOptions';
import { registerThemingParticipant, IThemeService, ITheme, getThemeTypeSelector } from 'vs/platform/theme/common/themeService';
import { scrollbarShadow, diffInserted, diffRemoved, defaultInsertColor, defaultRemoveColor, diffInsertedOutline, diffRemovedOutline, diffBorder } from 'vs/platform/theme/common/colorRegistry';
import { RunOnceScheduler } from 'vs/base/common/async';
import { Color } from 'vs/base/common/color';
import { OverviewRulerZone } from 'vs/editor/common/view/overviewZoneManager';
import { IEditorWhitespace } from 'vs/editor/common/viewLayout/whitespaceComputer';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
import { DiffReview } from 'vs/editor/browser/widget/diffReview';
import URI from 'vs/base/common/uri';
import { IStringBuilder, createStringBuilder } from 'vs/editor/common/core/stringBuilder';
import { IModelDeltaDecoration, IModelDecorationsChangeAccessor, ITextModel } from 'vs/editor/common/model';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { Emitter, Event } from 'vs/base/common/event';
import { Disposable } from 'vs/base/common/lifecycle';
import * as objects from 'vs/base/common/objects';
import { URI } from 'vs/base/common/uri';
import { Configuration } from 'vs/editor/browser/config/configuration';
import { StableEditorScrollState } from 'vs/editor/browser/core/editorState';
import * as editorBrowser from 'vs/editor/browser/editorBrowser';
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
import { CodeEditorWidget } from 'vs/editor/browser/widget/codeEditorWidget';
import { DiffReview } from 'vs/editor/browser/widget/diffReview';
import * as editorOptions from 'vs/editor/common/config/editorOptions';
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 { IStringBuilder, createStringBuilder } from 'vs/editor/common/core/stringBuilder';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { IModelDecorationsChangeAccessor, IModelDeltaDecoration, ITextModel } from 'vs/editor/common/model';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
import { IDiffComputationResult, IEditorWorkerService } from 'vs/editor/common/services/editorWorkerService';
import { OverviewRulerZone } from 'vs/editor/common/view/overviewZoneManager';
import { LineDecoration } from 'vs/editor/common/viewLayout/lineDecorations';
import { RenderLineInput, renderViewLine } from 'vs/editor/common/viewLayout/viewLineRenderer';
import { IEditorWhitespace } from 'vs/editor/common/viewLayout/whitespaceComputer';
import { InlineDecoration, InlineDecorationType, ViewLineRenderingData } from 'vs/editor/common/viewModel/viewModel';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { defaultInsertColor, defaultRemoveColor, diffBorder, diffInserted, diffInsertedOutline, diffRemoved, diffRemovedOutline, scrollbarShadow } from 'vs/platform/theme/common/colorRegistry';
import { ITheme, IThemeService, getThemeTypeSelector, registerThemingParticipant } from 'vs/platform/theme/common/themeService';
interface IEditorDiffDecorations {
decorations: IModelDeltaDecoration[];
@@ -173,7 +171,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
private _currentlyChangingViewZones: boolean;
private _beginUpdateDecorationsTimeout: number;
private _diffComputationToken: number;
private _lineChanges: editorCommon.ILineChange[];
private _diffComputationResult: IDiffComputationResult | null;
private _isVisible: boolean;
private _isHandlingScrollEvent: boolean;
@@ -283,7 +281,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
this._height = 0;
this._reviewHeight = 0;
this._lineChanges = null;
this._diffComputationResult = null;
const leftContextKeyService = this._contextKeyService.createScoped();
leftContextKeyService.createKey('isInDiffLeftEditor', true);
@@ -525,8 +523,11 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
return editorCommon.EditorType.IDiffEditor;
}
public getLineChanges(): editorCommon.ILineChange[] {
return this._lineChanges;
public getLineChanges(): editorCommon.ILineChange[] | null {
if (!this._diffComputationResult) {
return null;
}
return this._diffComputationResult.changes;
}
public getOriginalEditor(): editorBrowser.ICodeEditor {
@@ -585,7 +586,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
// renderSideBySide
if (renderSideBySideChanged) {
if (this._renderSideBySide) {
this._setStrategy(new DiffEdtorWidgetSideBySide(this._createDataSource(), this._enableSplitViewResizing, ));
this._setStrategy(new DiffEdtorWidgetSideBySide(this._createDataSource(), this._enableSplitViewResizing));
} else {
this._setStrategy(new DiffEdtorWidgetInline(this._createDataSource(), this._enableSplitViewResizing));
}
@@ -621,7 +622,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
}
// Disable any diff computations that will come in
this._lineChanges = null;
this._diffComputationResult = null;
this._diffComputationToken++;
if (model) {
@@ -630,7 +631,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
// Begin comparing
this._beginUpdateDecorations();
} else {
this._lineChanges = null;
this._diffComputationResult = null;
}
this._layoutOverviewViewport();
@@ -644,7 +645,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
return this.modifiedEditor.getVisibleColumnFromPosition(position);
}
public getPosition(): Position {
public getPosition(): Position | null {
return this.modifiedEditor.getPosition();
}
@@ -676,11 +677,11 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
this.modifiedEditor.revealPositionInCenterIfOutsideViewport(position, scrollType);
}
public getSelection(): Selection {
public getSelection(): Selection | null {
return this.modifiedEditor.getSelection();
}
public getSelections(): Selection[] {
public getSelections(): Selection[] | null {
return this.modifiedEditor.getSelections();
}
@@ -849,10 +850,10 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
this._beginUpdateDecorationsTimeout = window.setTimeout(() => this._beginUpdateDecorations(), DiffEditorWidget.UPDATE_DIFF_DECORATIONS_DELAY);
}
private _lastOriginalWarning: URI = null;
private _lastModifiedWarning: URI = null;
private _lastOriginalWarning: URI | null = null;
private _lastModifiedWarning: URI | null = null;
private static _equals(a: URI, b: URI): boolean {
private static _equals(a: URI | null, b: URI | null): boolean {
if (!a && !b) {
return true;
}
@@ -893,7 +894,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
&& currentOriginalModel === this.originalEditor.getModel()
&& currentModifiedModel === this.modifiedEditor.getModel()
) {
this._lineChanges = result;
this._diffComputationResult = result;
this._updateDecorationsRunner.schedule();
this._onDidUpdateDiff.fire();
}
@@ -902,7 +903,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
&& currentOriginalModel === this.originalEditor.getModel()
&& currentModifiedModel === this.modifiedEditor.getModel()
) {
this._lineChanges = null;
this._diffComputationResult = null;
this._updateDecorationsRunner.schedule();
}
});
@@ -917,7 +918,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
if (!this.originalEditor.getModel() || !this.modifiedEditor.getModel()) {
return;
}
let lineChanges = this._lineChanges || [];
const lineChanges = (this._diffComputationResult ? this._diffComputationResult.changes : []);
let foreignOriginal = this._originalEditorState.getForeignViewZones(this.originalEditor.getWhitespaces());
let foreignModified = this._modifiedEditorState.getForeignViewZones(this.modifiedEditor.getWhitespaces());
@@ -944,7 +945,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
clonedOptions.folding = false;
clonedOptions.codeLens = false;
clonedOptions.fixedOverflowWidgets = true;
clonedOptions.lineDecorationsWidth = '2ch';
// clonedOptions.lineDecorationsWidth = '2ch';
if (!clonedOptions.minimap) {
clonedOptions.minimap = {};
}
@@ -1011,7 +1012,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
}
}
private _computeOverviewViewport(): { height: number; top: number; } {
private _computeOverviewViewport(): { height: number; top: number; } | null {
let layoutInfo = this.modifiedEditor.getLayoutInfo();
if (!layoutInfo) {
return null;
@@ -1069,7 +1070,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
this._strategy = newStrategy;
newStrategy.applyColors(this._themeService.getTheme());
if (this._lineChanges) {
if (this._diffComputationResult) {
this._updateDecorations();
}
@@ -1077,17 +1078,18 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
this._measureDomElement(true);
}
private _getLineChangeAtOrBeforeLineNumber(lineNumber: number, startLineNumberExtractor: (lineChange: editorCommon.ILineChange) => number): editorCommon.ILineChange {
if (this._lineChanges.length === 0 || lineNumber < startLineNumberExtractor(this._lineChanges[0])) {
private _getLineChangeAtOrBeforeLineNumber(lineNumber: number, startLineNumberExtractor: (lineChange: editorCommon.ILineChange) => number): editorCommon.ILineChange | null {
const lineChanges = (this._diffComputationResult ? this._diffComputationResult.changes : []);
if (lineChanges.length === 0 || lineNumber < startLineNumberExtractor(lineChanges[0])) {
// There are no changes or `lineNumber` is before the first change
return null;
}
let min = 0, max = this._lineChanges.length - 1;
let min = 0, max = lineChanges.length - 1;
while (min < max) {
let mid = Math.floor((min + max) / 2);
let midStart = startLineNumberExtractor(this._lineChanges[mid]);
let midEnd = (mid + 1 <= max ? startLineNumberExtractor(this._lineChanges[mid + 1]) : Number.MAX_VALUE);
let midStart = startLineNumberExtractor(lineChanges[mid]);
let midEnd = (mid + 1 <= max ? startLineNumberExtractor(lineChanges[mid + 1]) : Number.MAX_VALUE);
if (lineNumber < midStart) {
max = mid - 1;
@@ -1099,7 +1101,7 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
max = mid;
}
}
return this._lineChanges[min];
return lineChanges[min];
}
private _getEquivalentLineForOriginalLineNumber(lineNumber: number): number {
@@ -1146,8 +1148,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
return originalEquivalentLineNumber + lineChangeOriginalLength - lineChangeModifiedLength + delta;
}
public getDiffLineInformationForOriginal(lineNumber: number): editorBrowser.IDiffLineInformation {
if (!this._lineChanges) {
public getDiffLineInformationForOriginal(lineNumber: number): editorBrowser.IDiffLineInformation | null {
if (!this._diffComputationResult) {
// Cannot answer that which I don't know
return null;
}
@@ -1156,8 +1158,8 @@ export class DiffEditorWidget extends Disposable implements editorBrowser.IDiffE
};
}
public getDiffLineInformationForModified(lineNumber: number): editorBrowser.IDiffLineInformation {
if (!this._lineChanges) {
public getDiffLineInformationForModified(lineNumber: number): editorBrowser.IDiffLineInformation | null {
if (!this._diffComputationResult) {
// Cannot answer that which I don't know
return null;
}
@@ -1233,15 +1235,20 @@ abstract class DiffEditorWidgetStyle extends Disposable implements IDiffEditorWi
public abstract layout(): number;
}
interface IMyViewZone extends editorBrowser.IViewZone {
interface IMyViewZone {
shouldNotShrink?: boolean;
afterLineNumber: number;
heightInLines: number;
minWidthInPx?: number;
domNode: HTMLElement | null;
marginDomNode?: HTMLElement | null;
}
class ForeignViewZonesIterator {
private _index: number;
private _source: IEditorWhitespace[];
public current: IEditorWhitespace;
public current: IEditorWhitespace | null;
constructor(source: IEditorWhitespace[]) {
this._source = source;
@@ -1272,7 +1279,7 @@ abstract class ViewZonesComputer {
}
public getViewZones(): IEditorsZones {
let result: IEditorsZones = {
let result: { original: IMyViewZone[]; modified: IMyViewZone[]; } = {
original: [],
modified: []
};
@@ -1288,7 +1295,7 @@ abstract class ViewZonesComputer {
return a.afterLineNumber - b.afterLineNumber;
};
let addAndCombineIfPossible = (destination: editorBrowser.IViewZone[], item: IMyViewZone) => {
let addAndCombineIfPossible = (destination: IMyViewZone[], item: IMyViewZone) => {
if (item.domNode === null && destination.length > 0) {
let lastItem = destination[destination.length - 1];
if (lastItem.afterLineNumber === item.afterLineNumber && lastItem.domNode === null) {
@@ -1335,10 +1342,17 @@ abstract class ViewZonesComputer {
} else {
viewZoneLineNumber = originalEndEquivalentLineNumber;
}
let marginDomNode: HTMLDivElement | null = null;
if (lineChange && lineChange.modifiedStartLineNumber <= modifiedForeignVZ.current.afterLineNumber && modifiedForeignVZ.current.afterLineNumber <= lineChange.modifiedEndLineNumber) {
marginDomNode = this._createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion();
}
stepOriginal.push({
afterLineNumber: viewZoneLineNumber,
heightInLines: modifiedForeignVZ.current.heightInLines,
domNode: null
domNode: null,
marginDomNode: marginDomNode
});
modifiedForeignVZ.advance();
}
@@ -1444,9 +1458,11 @@ abstract class ViewZonesComputer {
return result;
}
protected abstract _produceOriginalFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone;
protected abstract _createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion(): HTMLDivElement | null;
protected abstract _produceModifiedFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone;
protected abstract _produceOriginalFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null;
protected abstract _produceModifiedFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null;
}
function createDecoration(startLineNumber: number, startColumn: number, endLineNumber: number, endColumn: number, options: ModelDecorationOptions) {
@@ -1737,7 +1753,11 @@ class SideBySideViewZonesComputer extends ViewZonesComputer {
super(lineChanges, originalForeignVZ, modifiedForeignVZ);
}
protected _produceOriginalFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone {
protected _createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion(): HTMLDivElement | null {
return null;
}
protected _produceOriginalFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null {
if (lineChangeModifiedLength > lineChangeOriginalLength) {
return {
afterLineNumber: Math.max(lineChange.originalStartLineNumber, lineChange.originalEndLineNumber),
@@ -1748,7 +1768,7 @@ class SideBySideViewZonesComputer extends ViewZonesComputer {
return null;
}
protected _produceModifiedFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone {
protected _produceModifiedFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null {
if (lineChangeOriginalLength > lineChangeModifiedLength) {
return {
afterLineNumber: Math.max(lineChange.modifiedStartLineNumber, lineChange.modifiedEndLineNumber),
@@ -1897,10 +1917,15 @@ class InlineViewZonesComputer extends ViewZonesComputer {
this.renderIndicators = renderIndicators;
}
protected _produceOriginalFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone {
protected _createOriginalMarginDomNodeForModifiedForeignViewZoneInAddedRegion(): HTMLDivElement | null {
let result = document.createElement('div');
result.className = 'inline-added-margin-view-zone';
return result;
}
protected _produceOriginalFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null {
let marginDomNode = document.createElement('div');
marginDomNode.className = 'inline-added-margin-view-zone';
Configuration.applyFontInfoSlow(marginDomNode, this.modifiedEditorConfiguration.fontInfo);
return {
afterLineNumber: Math.max(lineChange.originalStartLineNumber, lineChange.originalEndLineNumber),
@@ -1910,7 +1935,7 @@ class InlineViewZonesComputer extends ViewZonesComputer {
};
}
protected _produceModifiedFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone {
protected _produceModifiedFromDiff(lineChange: editorCommon.ILineChange, lineChangeOriginalLength: number, lineChangeModifiedLength: number): IMyViewZone | null {
let decorations: InlineDecoration[] = [];
if (lineChange.charChanges) {
for (let j = 0, lengthJ = lineChange.charChanges.length; j < lengthJ; j++) {
@@ -1982,6 +2007,7 @@ class InlineViewZonesComputer extends ViewZonesComputer {
const containsRTL = ViewLineRenderingData.containsRTL(lineContent, isBasicASCII, originalModel.mightContainRTL());
const output = renderViewLine(new RenderLineInput(
(config.fontInfo.isMonospace && !config.viewInfo.disableMonospaceOptimizations),
config.fontInfo.canUseHalfwidthRightwardsArrow,
lineContent,
false,
isBasicASCII,
@@ -2048,7 +2074,7 @@ registerThemingParticipant((theme, collector) => {
collector.addRule(`.monaco-diff-editor.side-by-side .editor.modified { box-shadow: -6px 0 5px -5px ${shadow}; }`);
}
let border = theme.getColor(diffBorder);
const border = theme.getColor(diffBorder);
if (border) {
collector.addRule(`.monaco-diff-editor.side-by-side .editor.modified { border-left: 1px solid ${border}; }`);
}