@@ -10,7 +10,7 @@ import { TestRPCProtocol } from 'vs/workbench/test/browser/api/testRPCProtocol';
1010import { DisposableStore } from 'vs/base/common/lifecycle' ;
1111import { NullLogService } from 'vs/platform/log/common/log' ;
1212import { mock } from 'vs/base/test/common/mock' ;
13- import { MainContext , MainThreadCommandsShape , MainThreadNotebookShape } from 'vs/workbench/api/common/extHost.protocol' ;
13+ import { IModelAddedData , MainContext , MainThreadCommandsShape , MainThreadNotebookShape } from 'vs/workbench/api/common/extHost.protocol' ;
1414import { ExtHostNotebookDocument , ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook' ;
1515import { CellKind , CellUri , NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
1616import { URI } from 'vs/base/common/uri' ;
@@ -47,7 +47,7 @@ suite('NotebookCell#Document', function () {
4747 let reg = extHostNotebooks . registerNotebookContentProvider ( nullExtensionDescription , 'test' , new class extends mock < vscode . NotebookContentProvider > ( ) {
4848 // async openNotebook() { }
4949 } ) ;
50- await extHostNotebooks . $acceptDocumentAndEditorsDelta ( {
50+ extHostNotebooks . $acceptDocumentAndEditorsDelta ( {
5151 addedDocuments : [ {
5252 handle : 0 ,
5353 uri : notebookUri ,
@@ -77,7 +77,7 @@ suite('NotebookCell#Document', function () {
7777 selections : [ 0 ]
7878 } ]
7979 } ) ;
80- await extHostNotebooks . $acceptDocumentAndEditorsDelta ( { newActiveEditor : '_notebook_editor_0' } ) ;
80+ extHostNotebooks . $acceptDocumentAndEditorsDelta ( { newActiveEditor : '_notebook_editor_0' } ) ;
8181
8282 notebook = extHostNotebooks . notebookDocuments [ 0 ] ! ;
8383
@@ -116,7 +116,7 @@ suite('NotebookCell#Document', function () {
116116 removedCellUris . push ( doc . uri . toString ( ) ) ;
117117 } ) ;
118118
119- await extHostNotebooks . $acceptDocumentAndEditorsDelta ( { removedDocuments : [ notebook . uri ] } ) ;
119+ extHostNotebooks . $acceptDocumentAndEditorsDelta ( { removedDocuments : [ notebook . uri ] } ) ;
120120 reg . dispose ( ) ;
121121
122122 assert . strictEqual ( removedCellUris . length , 2 ) ;
@@ -174,4 +174,45 @@ suite('NotebookCell#Document', function () {
174174 await p ;
175175
176176 } ) ;
177+
178+ test ( 'cell document stays open when notebook is still open' , async function ( ) {
179+
180+ const docs : vscode . TextDocument [ ] = [ ] ;
181+ const addData : IModelAddedData [ ] = [ ] ;
182+ for ( let cell of notebook . cells ) {
183+ const doc = extHostDocuments . getDocument ( cell . uri ) ;
184+ assert . ok ( doc ) ;
185+ assert . equal ( extHostDocuments . getDocument ( cell . uri ) . isClosed , false ) ;
186+ docs . push ( doc ) ;
187+ addData . push ( {
188+ EOL : '\n' ,
189+ isDirty : doc . isDirty ,
190+ lines : doc . getText ( ) . split ( '\n' ) ,
191+ modeId : doc . languageId ,
192+ uri : doc . uri ,
193+ versionId : doc . version
194+ } ) ;
195+ }
196+
197+ // this call happens when opening a document on the main side
198+ extHostDocumentsAndEditors . $acceptDocumentsAndEditorsDelta ( { addedDocuments : addData } ) ;
199+
200+ // this call happens when closing a document from the main side
201+ extHostDocumentsAndEditors . $acceptDocumentsAndEditorsDelta ( { removedDocuments : docs . map ( d => d . uri ) } ) ;
202+
203+ // notebook is still open -> cell documents stay open
204+ for ( let cell of notebook . cells ) {
205+ assert . ok ( extHostDocuments . getDocument ( cell . uri ) ) ;
206+ assert . equal ( extHostDocuments . getDocument ( cell . uri ) . isClosed , false ) ;
207+ }
208+
209+ // close notebook -> docs are closed
210+ extHostNotebooks . $acceptDocumentAndEditorsDelta ( { removedDocuments : [ notebook . uri ] } ) ;
211+ for ( let cell of notebook . cells ) {
212+ assert . throws ( ( ) => extHostDocuments . getDocument ( cell . uri ) ) ;
213+ }
214+ for ( let doc of docs ) {
215+ assert . equal ( doc . isClosed , true ) ;
216+ }
217+ } ) ;
177218} ) ;
0 commit comments