Skip to content

Commit ca46ba0

Browse files
committed
Revert "Fixes microsoft#145872: Emit model events using the view model outgoing queue"
This reverts commit 00b43ac.
1 parent da0e0ae commit ca46ba0

File tree

6 files changed

+34
-306
lines changed

6 files changed

+34
-306
lines changed

src/vs/editor/browser/editorBrowser.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Selection } from 'vs/editor/common/core/selection';
1414
import * as editorCommon from 'vs/editor/common/editorCommon';
1515
import { IIdentifiedSingleEditOperation, IModelDecoration, IModelDeltaDecoration, ITextModel, ICursorStateComputer, PositionAffinity } from 'vs/editor/common/model';
1616
import { IWordAtPosition } from 'vs/editor/common/core/wordHelper';
17-
import { IModelContentChangedEvent, IModelDecorationsChangedEvent, IModelLanguageChangedEvent, IModelLanguageConfigurationChangedEvent, IModelOptionsChangedEvent, IModelTokensChangedEvent } from 'vs/editor/common/textModelEvents';
17+
import { IModelContentChangedEvent, IModelDecorationsChangedEvent, IModelLanguageChangedEvent, IModelLanguageConfigurationChangedEvent, IModelOptionsChangedEvent } from 'vs/editor/common/textModelEvents';
1818
import { OverviewRulerZone } from 'vs/editor/common/viewModel/overviewZoneManager';
1919
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
2020
import { IEditorWhitespace, IViewModel } from 'vs/editor/common/viewModel';
@@ -531,11 +531,6 @@ export interface ICodeEditor extends editorCommon.IEditor {
531531
* @event
532532
*/
533533
readonly onDidChangeModelDecorations: Event<IModelDecorationsChangedEvent>;
534-
/**
535-
* An event emitted when the tokens of the current model have changed.
536-
* @internal
537-
*/
538-
readonly onDidChangeModelTokens: Event<IModelTokensChangedEvent>;
539534
/**
540535
* An event emitted when the text inside this editor gained focus (i.e. cursor starts blinking).
541536
* @event

src/vs/editor/browser/widget/codeEditorWidget.ts

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { EndOfLinePreference, IIdentifiedSingleEditOperation, IModelDecoration,
3737
import { IWordAtPosition } from 'vs/editor/common/core/wordHelper';
3838
import { ClassName } from 'vs/editor/common/model/intervalTree';
3939
import { ModelDecorationOptions } from 'vs/editor/common/model/textModel';
40-
import { IModelContentChangedEvent, IModelDecorationsChangedEvent, IModelLanguageChangedEvent, IModelLanguageConfigurationChangedEvent, IModelOptionsChangedEvent, IModelTokensChangedEvent } from 'vs/editor/common/textModelEvents';
40+
import { IModelContentChangedEvent, IModelDecorationsChangedEvent, IModelLanguageChangedEvent, IModelLanguageConfigurationChangedEvent, IModelOptionsChangedEvent } from 'vs/editor/common/textModelEvents';
4141
import { editorUnnecessaryCodeBorder, editorUnnecessaryCodeOpacity } from 'vs/editor/common/core/editorColorRegistry';
4242
import { editorErrorBorder, editorErrorForeground, editorHintBorder, editorHintForeground, editorInfoBorder, editorInfoForeground, editorWarningBorder, editorWarningForeground, editorForeground, editorErrorBackground, editorInfoBackground, editorWarningBackground } from 'vs/platform/theme/common/colorRegistry';
4343
import { VerticalRevealType } from 'vs/editor/common/viewEvents';
@@ -134,9 +134,6 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
134134
private readonly _onDidChangeModelDecorations: Emitter<IModelDecorationsChangedEvent> = this._register(new Emitter<IModelDecorationsChangedEvent>());
135135
public readonly onDidChangeModelDecorations: Event<IModelDecorationsChangedEvent> = this._onDidChangeModelDecorations.event;
136136

137-
private readonly _onDidChangeModelTokens: Emitter<IModelTokensChangedEvent> = this._register(new Emitter<IModelTokensChangedEvent>());
138-
public readonly onDidChangeModelTokens: Event<IModelTokensChangedEvent> = this._onDidChangeModelTokens.event;
139-
140137
private readonly _onDidChangeConfiguration: Emitter<ConfigurationChangedEvent> = this._register(new Emitter<ConfigurationChangedEvent>());
141138
public readonly onDidChangeConfiguration: Event<ConfigurationChangedEvent> = this._onDidChangeConfiguration.event;
142139

@@ -1590,6 +1587,14 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
15901587
this._themeService
15911588
);
15921589

1590+
listenersToRemove.push(model.onDidChangeDecorations((e) => this._onDidChangeModelDecorations.fire(e)));
1591+
listenersToRemove.push(model.onDidChangeLanguage((e) => {
1592+
this._domElement.setAttribute('data-mode-id', model.getLanguageId());
1593+
this._onDidChangeModelLanguage.fire(e);
1594+
}));
1595+
listenersToRemove.push(model.onDidChangeLanguageConfiguration((e) => this._onDidChangeModelLanguageConfiguration.fire(e)));
1596+
listenersToRemove.push(model.onDidChangeContent((e) => this._onDidChangeModelContent.fire(e)));
1597+
listenersToRemove.push(model.onDidChangeOptions((e) => this._onDidChangeModelOptions.fire(e)));
15931598
// Someone might destroy the model from under the editor, so prevent any exceptions by setting a null model
15941599
listenersToRemove.push(model.onWillDispose(() => this.setModel(null)));
15951600

@@ -1644,25 +1649,6 @@ export class CodeEditorWidget extends Disposable implements editorBrowser.ICodeE
16441649

16451650
break;
16461651
}
1647-
case OutgoingViewModelEventKind.ModelDecorationsChanged:
1648-
this._onDidChangeModelDecorations.fire(e.event);
1649-
break;
1650-
case OutgoingViewModelEventKind.ModelLanguageChanged:
1651-
this._domElement.setAttribute('data-mode-id', model.getLanguageId());
1652-
this._onDidChangeModelLanguage.fire(e.event);
1653-
break;
1654-
case OutgoingViewModelEventKind.ModelLanguageConfigurationChanged:
1655-
this._onDidChangeModelLanguageConfiguration.fire(e.event);
1656-
break;
1657-
case OutgoingViewModelEventKind.ModelContentChanged:
1658-
this._onDidChangeModelContent.fire(e.event);
1659-
break;
1660-
case OutgoingViewModelEventKind.ModelOptionsChanged:
1661-
this._onDidChangeModelOptions.fire(e.event);
1662-
break;
1663-
case OutgoingViewModelEventKind.ModelTokensChanged:
1664-
this._onDidChangeModelTokens.fire(e.event);
1665-
break;
16661652

16671653
}
16681654
}));

src/vs/editor/common/viewModel/viewModelImpl.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { ILineBreaksComputer, ILineBreaksComputerFactory, InjectedText } from 'v
3535
import { ViewEventHandler } from 'vs/editor/common/viewEventHandler';
3636
import { ICoordinatesConverter, IViewModel, IWhitespaceChangeAccessor, MinimapLinesRenderingData, OverviewRulerDecorationsGroup, ViewLineData, ViewLineRenderingData, ViewModelDecoration } from 'vs/editor/common/viewModel';
3737
import { ViewModelDecorations } from 'vs/editor/common/viewModel/viewModelDecorations';
38-
import { FocusChangedEvent, ModelContentChangedEvent, ModelDecorationsChangedEvent, ModelLanguageChangedEvent, ModelLanguageConfigurationChangedEvent, ModelOptionsChangedEvent, ModelTokensChangedEvent, OutgoingViewModelEvent, ReadOnlyEditAttemptEvent, ScrollChangedEvent, ViewModelEventDispatcher, ViewModelEventsCollector, ViewZonesChangedEvent } from 'vs/editor/common/viewModelEventDispatcher';
38+
import { FocusChangedEvent, OutgoingViewModelEvent, ReadOnlyEditAttemptEvent, ScrollChangedEvent, ViewModelEventDispatcher, ViewModelEventsCollector, ViewZonesChangedEvent } from 'vs/editor/common/viewModelEventDispatcher';
3939
import { IViewModelLines, ViewModelLinesFromModelAsIs, ViewModelLinesFromProjectedModel } from 'vs/editor/common/viewModel/viewModelLines';
4040
import { IThemeService } from 'vs/platform/theme/common/themeService';
4141

@@ -399,10 +399,6 @@ export class ViewModel extends Disposable implements IViewModel {
399399
this._tokenizeViewportSoon.schedule();
400400
}));
401401

402-
this._register(this.model.onDidChangeContent((e) => {
403-
this._eventDispatcher.emitOutgoingEvent(new ModelContentChangedEvent(e));
404-
}));
405-
406402
this._register(this.model.onDidChangeTokens((e) => {
407403
const viewRanges: { fromLineNumber: number; toLineNumber: number }[] = [];
408404
for (let j = 0, lenJ = e.ranges.length; j < lenJ; j++) {
@@ -419,20 +415,17 @@ export class ViewModel extends Disposable implements IViewModel {
419415
if (e.tokenizationSupportChanged) {
420416
this._tokenizeViewportSoon.schedule();
421417
}
422-
this._eventDispatcher.emitOutgoingEvent(new ModelTokensChangedEvent(e));
423418
}));
424419

425420
this._register(this.model.onDidChangeLanguageConfiguration((e) => {
426421
this._eventDispatcher.emitSingleViewEvent(new viewEvents.ViewLanguageConfigurationEvent());
427422
this.cursorConfig = new CursorConfiguration(this.model.getLanguageId(), this.model.getOptions(), this._configuration, this.languageConfigurationService);
428423
this._cursor.updateConfiguration(this.cursorConfig);
429-
this._eventDispatcher.emitOutgoingEvent(new ModelLanguageConfigurationChangedEvent(e));
430424
}));
431425

432426
this._register(this.model.onDidChangeLanguage((e) => {
433427
this.cursorConfig = new CursorConfiguration(this.model.getLanguageId(), this.model.getOptions(), this._configuration, this.languageConfigurationService);
434428
this._cursor.updateConfiguration(this.cursorConfig);
435-
this._eventDispatcher.emitOutgoingEvent(new ModelLanguageChangedEvent(e));
436429
}));
437430

438431
this._register(this.model.onDidChangeOptions((e) => {
@@ -454,14 +447,11 @@ export class ViewModel extends Disposable implements IViewModel {
454447

455448
this.cursorConfig = new CursorConfiguration(this.model.getLanguageId(), this.model.getOptions(), this._configuration, this.languageConfigurationService);
456449
this._cursor.updateConfiguration(this.cursorConfig);
457-
458-
this._eventDispatcher.emitOutgoingEvent(new ModelOptionsChangedEvent(e));
459450
}));
460451

461452
this._register(this.model.onDidChangeDecorations((e) => {
462453
this._decorations.onModelDecorationsChanged();
463454
this._eventDispatcher.emitSingleViewEvent(new viewEvents.ViewDecorationsChangedEvent(e));
464-
this._eventDispatcher.emitOutgoingEvent(new ModelDecorationsChangedEvent(e));
465455
}));
466456
}
467457

src/vs/editor/common/viewModelEventDispatcher.ts

Lines changed: 18 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { Emitter } from 'vs/base/common/event';
1010
import { Selection } from 'vs/editor/common/core/selection';
1111
import { Disposable } from 'vs/base/common/lifecycle';
1212
import { CursorChangeReason } from 'vs/editor/common/cursorEvents';
13-
import { IModelContentChangedEvent, IModelDecorationsChangedEvent, IModelLanguageChangedEvent, IModelLanguageConfigurationChangedEvent, IModelOptionsChangedEvent, IModelTokensChangedEvent } from 'vs/editor/common/textModelEvents';
1413

1514
export class ViewModelEventDispatcher extends Disposable {
1615

@@ -41,9 +40,8 @@ export class ViewModelEventDispatcher extends Disposable {
4140

4241
private _addOutgoingEvent(e: OutgoingViewModelEvent): void {
4342
for (let i = 0, len = this._outgoingEvents.length; i < len; i++) {
44-
const mergeResult = (this._outgoingEvents[i].kind === e.kind ? this._outgoingEvents[i].attemptToMerge(e) : null);
45-
if (mergeResult) {
46-
this._outgoingEvents[i] = mergeResult;
43+
if (this._outgoingEvents[i].kind === e.kind) {
44+
this._outgoingEvents[i] = this._outgoingEvents[i].merge(e);
4745
return;
4846
}
4947
}
@@ -181,12 +179,6 @@ export type OutgoingViewModelEvent = (
181179
| HiddenAreasChangedEvent
182180
| ReadOnlyEditAttemptEvent
183181
| CursorStateChangedEvent
184-
| ModelDecorationsChangedEvent
185-
| ModelLanguageChangedEvent
186-
| ModelLanguageConfigurationChangedEvent
187-
| ModelContentChangedEvent
188-
| ModelOptionsChangedEvent
189-
| ModelTokensChangedEvent
190182
);
191183

192184
export const enum OutgoingViewModelEventKind {
@@ -197,12 +189,6 @@ export const enum OutgoingViewModelEventKind {
197189
HiddenAreasChanged,
198190
ReadOnlyEditAttempt,
199191
CursorStateChanged,
200-
ModelDecorationsChanged,
201-
ModelLanguageChanged,
202-
ModelLanguageConfigurationChanged,
203-
ModelContentChanged,
204-
ModelOptionsChanged,
205-
ModelTokensChanged,
206192
}
207193

208194
export class ContentSizeChangedEvent implements IContentSizeChangedEvent {
@@ -230,9 +216,10 @@ export class ContentSizeChangedEvent implements IContentSizeChangedEvent {
230216
return (!this.contentWidthChanged && !this.contentHeightChanged);
231217
}
232218

233-
public attemptToMerge(other: OutgoingViewModelEvent): OutgoingViewModelEvent | null {
234-
if (other.kind !== this.kind) {
235-
return null;
219+
220+
public merge(other: OutgoingViewModelEvent): ContentSizeChangedEvent {
221+
if (other.kind !== OutgoingViewModelEventKind.ContentSizeChanged) {
222+
return this;
236223
}
237224
return new ContentSizeChangedEvent(this._oldContentWidth, this._oldContentHeight, other.contentWidth, other.contentHeight);
238225
}
@@ -254,9 +241,9 @@ export class FocusChangedEvent {
254241
return (this.oldHasFocus === this.hasFocus);
255242
}
256243

257-
public attemptToMerge(other: OutgoingViewModelEvent): OutgoingViewModelEvent | null {
258-
if (other.kind !== this.kind) {
259-
return null;
244+
public merge(other: OutgoingViewModelEvent): FocusChangedEvent {
245+
if (other.kind !== OutgoingViewModelEventKind.FocusChanged) {
246+
return this;
260247
}
261248
return new FocusChangedEvent(this.oldHasFocus, other.hasFocus);
262249
}
@@ -305,9 +292,9 @@ export class ScrollChangedEvent {
305292
return (!this.scrollWidthChanged && !this.scrollLeftChanged && !this.scrollHeightChanged && !this.scrollTopChanged);
306293
}
307294

308-
public attemptToMerge(other: OutgoingViewModelEvent): OutgoingViewModelEvent | null {
309-
if (other.kind !== this.kind) {
310-
return null;
295+
public merge(other: OutgoingViewModelEvent): ScrollChangedEvent {
296+
if (other.kind !== OutgoingViewModelEventKind.ScrollChanged) {
297+
return this;
311298
}
312299
return new ScrollChangedEvent(
313300
this._oldScrollWidth, this._oldScrollLeft, this._oldScrollHeight, this._oldScrollTop,
@@ -327,10 +314,7 @@ export class ViewZonesChangedEvent {
327314
return false;
328315
}
329316

330-
public attemptToMerge(other: OutgoingViewModelEvent): OutgoingViewModelEvent | null {
331-
if (other.kind !== this.kind) {
332-
return null;
333-
}
317+
public merge(other: OutgoingViewModelEvent): ViewZonesChangedEvent {
334318
return this;
335319
}
336320
}
@@ -346,10 +330,7 @@ export class HiddenAreasChangedEvent {
346330
return false;
347331
}
348332

349-
public attemptToMerge(other: OutgoingViewModelEvent): OutgoingViewModelEvent | null {
350-
if (other.kind !== this.kind) {
351-
return null;
352-
}
333+
public merge(other: OutgoingViewModelEvent): HiddenAreasChangedEvent {
353334
return this;
354335
}
355336
}
@@ -403,9 +384,9 @@ export class CursorStateChangedEvent {
403384
);
404385
}
405386

406-
public attemptToMerge(other: OutgoingViewModelEvent): OutgoingViewModelEvent | null {
407-
if (other.kind !== this.kind) {
408-
return null;
387+
public merge(other: OutgoingViewModelEvent): CursorStateChangedEvent {
388+
if (other.kind !== OutgoingViewModelEventKind.CursorStateChanged) {
389+
return this;
409390
}
410391
return new CursorStateChangedEvent(
411392
this.oldSelections, other.selections, this.oldModelVersionId, other.modelVersionId, other.source, other.reason, this.reachedMaxCursorCount || other.reachedMaxCursorCount
@@ -424,106 +405,7 @@ export class ReadOnlyEditAttemptEvent {
424405
return false;
425406
}
426407

427-
public attemptToMerge(other: OutgoingViewModelEvent): OutgoingViewModelEvent | null {
428-
if (other.kind !== this.kind) {
429-
return null;
430-
}
408+
public merge(other: OutgoingViewModelEvent): ReadOnlyEditAttemptEvent {
431409
return this;
432410
}
433411
}
434-
435-
export class ModelDecorationsChangedEvent {
436-
public readonly kind = OutgoingViewModelEventKind.ModelDecorationsChanged;
437-
438-
constructor(
439-
public readonly event: IModelDecorationsChangedEvent
440-
) { }
441-
442-
public isNoOp(): boolean {
443-
return false;
444-
}
445-
446-
public attemptToMerge(other: OutgoingViewModelEvent): OutgoingViewModelEvent | null {
447-
return null;
448-
}
449-
}
450-
451-
export class ModelLanguageChangedEvent {
452-
public readonly kind = OutgoingViewModelEventKind.ModelLanguageChanged;
453-
454-
constructor(
455-
public readonly event: IModelLanguageChangedEvent
456-
) { }
457-
458-
public isNoOp(): boolean {
459-
return false;
460-
}
461-
462-
public attemptToMerge(other: OutgoingViewModelEvent): OutgoingViewModelEvent | null {
463-
return null;
464-
}
465-
}
466-
467-
export class ModelLanguageConfigurationChangedEvent {
468-
public readonly kind = OutgoingViewModelEventKind.ModelLanguageConfigurationChanged;
469-
470-
constructor(
471-
public readonly event: IModelLanguageConfigurationChangedEvent
472-
) { }
473-
474-
public isNoOp(): boolean {
475-
return false;
476-
}
477-
478-
public attemptToMerge(other: OutgoingViewModelEvent): OutgoingViewModelEvent | null {
479-
return null;
480-
}
481-
}
482-
483-
export class ModelContentChangedEvent {
484-
public readonly kind = OutgoingViewModelEventKind.ModelContentChanged;
485-
486-
constructor(
487-
public readonly event: IModelContentChangedEvent
488-
) { }
489-
490-
public isNoOp(): boolean {
491-
return false;
492-
}
493-
494-
public attemptToMerge(other: OutgoingViewModelEvent): OutgoingViewModelEvent | null {
495-
return null;
496-
}
497-
}
498-
499-
export class ModelOptionsChangedEvent {
500-
public readonly kind = OutgoingViewModelEventKind.ModelOptionsChanged;
501-
502-
constructor(
503-
public readonly event: IModelOptionsChangedEvent
504-
) { }
505-
506-
public isNoOp(): boolean {
507-
return false;
508-
}
509-
510-
public attemptToMerge(other: OutgoingViewModelEvent): OutgoingViewModelEvent | null {
511-
return null;
512-
}
513-
}
514-
515-
export class ModelTokensChangedEvent {
516-
public readonly kind = OutgoingViewModelEventKind.ModelTokensChanged;
517-
518-
constructor(
519-
public readonly event: IModelTokensChangedEvent
520-
) { }
521-
522-
public isNoOp(): boolean {
523-
return false;
524-
}
525-
526-
public attemptToMerge(other: OutgoingViewModelEvent): OutgoingViewModelEvent | null {
527-
return null;
528-
}
529-
}

src/vs/editor/test/browser/testCodeEditor.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,21 @@ export interface TestCodeEditorInstantiationOptions extends TestCodeEditorCreati
119119
serviceCollection?: ServiceCollection;
120120
}
121121

122-
export function withTestCodeEditor(text: ITextModel | string | string[] | ITextBufferFactory, options: TestCodeEditorInstantiationOptions, callback: (editor: ITestCodeEditor, viewModel: ViewModel, instantiationService: TestInstantiationService) => void): void {
122+
export function withTestCodeEditor(text: ITextModel | string | string[] | ITextBufferFactory, options: TestCodeEditorInstantiationOptions, callback: (editor: ITestCodeEditor, viewModel: ViewModel, instantiationService: IInstantiationService) => void): void {
123123
return _withTestCodeEditor(text, options, callback);
124124
}
125125

126-
export async function withAsyncTestCodeEditor(text: ITextModel | string | string[] | ITextBufferFactory, options: TestCodeEditorInstantiationOptions, callback: (editor: ITestCodeEditor, viewModel: ViewModel, instantiationService: TestInstantiationService) => Promise<void>): Promise<void> {
126+
export async function withAsyncTestCodeEditor(text: ITextModel | string | string[] | ITextBufferFactory, options: TestCodeEditorInstantiationOptions, callback: (editor: ITestCodeEditor, viewModel: ViewModel, instantiationService: IInstantiationService) => Promise<void>): Promise<void> {
127127
return _withTestCodeEditor(text, options, callback);
128128
}
129129

130130
function isTextModel(arg: ITextModel | string | string[] | ITextBufferFactory): arg is ITextModel {
131131
return Boolean(arg && (arg as ITextModel).uri);
132132
}
133133

134-
function _withTestCodeEditor(arg: ITextModel | string | string[] | ITextBufferFactory, options: TestCodeEditorInstantiationOptions, callback: (editor: ITestCodeEditor, viewModel: ViewModel, instantiationService: TestInstantiationService) => void): void;
135-
function _withTestCodeEditor(arg: ITextModel | string | string[] | ITextBufferFactory, options: TestCodeEditorInstantiationOptions, callback: (editor: ITestCodeEditor, viewModel: ViewModel, instantiationService: TestInstantiationService) => Promise<void>): Promise<void>;
136-
function _withTestCodeEditor(arg: ITextModel | string | string[] | ITextBufferFactory, options: TestCodeEditorInstantiationOptions, callback: (editor: ITestCodeEditor, viewModel: ViewModel, instantiationService: TestInstantiationService) => Promise<void> | void): Promise<void> | void {
134+
function _withTestCodeEditor(arg: ITextModel | string | string[] | ITextBufferFactory, options: TestCodeEditorInstantiationOptions, callback: (editor: ITestCodeEditor, viewModel: ViewModel, instantiationService: IInstantiationService) => void): void;
135+
function _withTestCodeEditor(arg: ITextModel | string | string[] | ITextBufferFactory, options: TestCodeEditorInstantiationOptions, callback: (editor: ITestCodeEditor, viewModel: ViewModel, instantiationService: IInstantiationService) => Promise<void>): Promise<void>;
136+
function _withTestCodeEditor(arg: ITextModel | string | string[] | ITextBufferFactory, options: TestCodeEditorInstantiationOptions, callback: (editor: ITestCodeEditor, viewModel: ViewModel, instantiationService: IInstantiationService) => Promise<void> | void): Promise<void> | void {
137137
const disposables = new DisposableStore();
138138
const instantiationService = createCodeEditorServices(disposables, options.serviceCollection);
139139
delete options.serviceCollection;

0 commit comments

Comments
 (0)