diff --git a/src/vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors.ts b/src/vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors.ts index 7bf94eb4027..56d4e237cd7 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors.ts @@ -27,9 +27,10 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; namespace mapset { export function newSet(from: Set): Set { - let ret = new Set(); - from.forEach(ret.add, ret); - return ret; + return new (Set)(from); + // let ret = new Set(); + // from.forEach(ret.add, ret); + // return ret; } export function setValues(set: Set): T[] { @@ -166,7 +167,7 @@ class MainThreadDocumentAndEditorStateComputer { @ICodeEditorService private _codeEditorService: ICodeEditorService, @IWorkbenchEditorService private _workbenchEditorService: IWorkbenchEditorService ) { - this._modelService.onModelAdded(this._updateState, this, this._toDispose); + this._modelService.onModelAdded(this._updateStateOnModelAdd, this, this._toDispose); this._modelService.onModelRemoved(this._updateState, this, this._toDispose); this._codeEditorService.onCodeEditorAdd(this._onDidAddEditor, this, this._toDispose); @@ -196,6 +197,32 @@ class MainThreadDocumentAndEditorStateComputer { } } + private _updateStateOnModelAdd(model: IModel): void { + if (model.isTooLargeForHavingARichMode()) { + // ignore + return; + } + + if (!this._currentState) { + // too early + this._updateState(); + return; + } + + // small (fast) delta + this._currentState = new DocumentAndEditorState( + this._currentState.documents.add(model), + this._currentState.editors, + this._currentState.activeEditor + ); + + this._onDidChangeState(new DocumentAndEditorStateDelta( + [], [model], + [], [], + this._currentState.activeEditor, this._currentState.activeEditor + )); + } + private _updateState(): void { // models: ignore too large models