diff --git a/src/vs/workbench/api/node/extHostDocumentsAndEditors.ts b/src/vs/workbench/api/node/extHostDocumentsAndEditors.ts index 164827a79fd369fa6dca9521e0f656ac3b714902..27baef47f89372dea0648b346ec9002c3b6351b7 100644 --- a/src/vs/workbench/api/node/extHostDocumentsAndEditors.ts +++ b/src/vs/workbench/api/node/extHostDocumentsAndEditors.ts @@ -98,6 +98,9 @@ export class ExtHostDocumentsAndEditors extends ExtHostDocumentsAndEditorsShape this._activeEditorId = delta.newActiveEditor; } + dispose(removedDocuments); + dispose(removedEditors); + // now that the internal state is complete, fire events if (delta.removedDocuments) { this._onDidRemoveDocuments.fire(removedDocuments); @@ -112,10 +115,6 @@ export class ExtHostDocumentsAndEditors extends ExtHostDocumentsAndEditorsShape if (delta.newActiveEditor !== undefined) { this._onDidChangeActiveTextEditor.fire(this.activeEditor()); } - - // now that the events are out, dispose removed documents and editors - dispose(removedDocuments); - dispose(removedEditors); } getDocument(strUrl: string): ExtHostDocumentData { diff --git a/src/vs/workbench/test/electron-browser/api/extHostDocumentsAndEditors.test.ts b/src/vs/workbench/test/electron-browser/api/extHostDocumentsAndEditors.test.ts new file mode 100644 index 0000000000000000000000000000000000000000..fc14d9e5382aa105f2e5fad75d5c91b7d584f598 --- /dev/null +++ b/src/vs/workbench/test/electron-browser/api/extHostDocumentsAndEditors.test.ts @@ -0,0 +1,63 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import * as assert from 'assert'; +import URI from 'vs/base/common/uri'; +import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/node/extHostDocumentsAndEditors'; +import { TPromise } from 'vs/base/common/winjs.base'; + + +suite('ExtHostDocumentsAndEditors', () => { + + let editors: ExtHostDocumentsAndEditors; + + setup(function () { + editors = new ExtHostDocumentsAndEditors({ + _serviceBrand: undefined, + get() { return undefined; }, + set() { } + }); + }); + + test('The value of TextDocument.isClosed is incorrect when a text document is closed, #27949', () => { + + editors.$acceptDocumentsAndEditorsDelta({ + addedDocuments: [{ + EOL: '\n', + isDirty: true, + modeId: 'fooLang', + url: URI.parse('foo:bar'), + versionId: 1, + lines: [ + 'first', + 'second' + ] + }] + }); + + return new TPromise((resolve, reject) => { + + editors.onDidRemoveDocuments(e => { + try { + + for (const data of e) { + assert.equal(data.document.isClosed, true); + } + resolve(undefined); + } catch (e) { + reject(e); + } + }); + + editors.$acceptDocumentsAndEditorsDelta({ + removedDocuments: ['foo:bar'] + }); + + }); + }); + +});