44 *--------------------------------------------------------------------------------------------*/
55
66import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers' ;
7- import { MainContext , MainThreadNotebookShape , NotebookExtensionDescription , IExtHostContext , ExtHostNotebookShape , ExtHostContext , INotebookDocumentsAndEditorsDelta } from '../common/extHost.protocol' ;
7+ import { MainContext , MainThreadNotebookShape , NotebookExtensionDescription , IExtHostContext , ExtHostNotebookShape , ExtHostContext , INotebookDocumentsAndEditorsDelta , INotebookModelAddedData } from '../common/extHost.protocol' ;
88import { Disposable , IDisposable , combinedDisposable } from 'vs/base/common/lifecycle' ;
99import { URI , UriComponents } from 'vs/base/common/uri' ;
1010import { INotebookService , IMainNotebookController } from 'vs/workbench/contrib/notebook/common/notebookService' ;
@@ -17,7 +17,6 @@ import { CancellationToken } from 'vs/base/common/cancellation';
1717import { IAccessibilityService } from 'vs/platform/accessibility/common/accessibility' ;
1818import { IRelativePattern } from 'vs/base/common/glob' ;
1919import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions' ;
20- import { generateUuid } from 'vs/base/common/uuid' ;
2120
2221export class MainThreadNotebookDocument extends Disposable {
2322 private _textModel : NotebookTextModel ;
@@ -30,11 +29,10 @@ export class MainThreadNotebookDocument extends Disposable {
3029 private readonly _proxy : ExtHostNotebookShape ,
3130 public handle : number ,
3231 public viewType : string ,
33- public uri : URI ,
34- public webviewId : string ,
32+ public uri : URI
3533 ) {
3634 super ( ) ;
37- this . _textModel = new NotebookTextModel ( handle , viewType , uri , webviewId ) ;
35+ this . _textModel = new NotebookTextModel ( handle , viewType , uri ) ;
3836 this . _register ( this . _textModel . onDidModelChange ( e => {
3937 this . _proxy . $acceptModelChanged ( this . uri , e ) ;
4038 } ) ) ;
@@ -189,6 +187,12 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
189187 } ) ) ;
190188 }
191189
190+ async addNotebookDocument ( data : INotebookModelAddedData ) {
191+ this . _proxy . $acceptDocumentAndEditorsDelta ( {
192+ addedDocuments : [ data ]
193+ } ) ;
194+ }
195+
192196 private _addNotebookEditor ( e : IEditor ) {
193197 this . _toDisposeOnEditorRemove . set ( e . getId ( ) , combinedDisposable (
194198 e . onDidChangeModel ( ( ) => this . _updateState ( ) ) ,
@@ -335,7 +339,7 @@ export class MainThreadNotebookController implements IMainNotebookController {
335339 ) {
336340 }
337341
338- async createNotebook ( viewType : string , uri : URI , backup : INotebookTextModelBackup | undefined , forceReload : boolean ) : Promise < NotebookTextModel | undefined > {
342+ async createNotebook ( viewType : string , uri : URI , backup : INotebookTextModelBackup | undefined , forceReload : boolean , editorId ?: string ) : Promise < NotebookTextModel | undefined > {
339343 let mainthreadNotebook = this . _mapping . get ( URI . from ( uri ) . toString ( ) ) ;
340344
341345 if ( mainthreadNotebook ) {
@@ -355,7 +359,7 @@ export class MainThreadNotebookController implements IMainNotebookController {
355359 return mainthreadNotebook . textModel ;
356360 }
357361
358- let document = new MainThreadNotebookDocument ( this . _proxy , MainThreadNotebookController . documentHandle ++ , viewType , uri , generateUuid ( ) ) ;
362+ let document = new MainThreadNotebookDocument ( this . _proxy , MainThreadNotebookController . documentHandle ++ , viewType , uri ) ;
359363 this . _mapping . set ( document . uri . toString ( ) , document ) ;
360364
361365 if ( backup ) {
@@ -367,28 +371,29 @@ export class MainThreadNotebookController implements IMainNotebookController {
367371 {
368372 editType : CellEditType . Insert ,
369373 index : 0 ,
370- cells : backup . cells
374+ cells : backup . cells || [ ]
371375 }
372376 ] ) ;
373377
374- await this . _proxy . $acceptDocumentAndEditorsDelta ( {
375- addedDocuments : [ {
376- viewType : document . viewType ,
377- handle : document . handle ,
378- webviewId : document . webviewId ,
379- uri : document . uri ,
380- metadata : document . textModel . metadata ,
381- versionId : document . textModel . versionId ,
382- cells : document . textModel . cells . map ( cell => ( {
383- handle : cell . handle ,
384- uri : cell . uri ,
385- source : cell . textBuffer . getLinesContent ( ) ,
386- language : cell . language ,
387- cellKind : cell . cellKind ,
388- outputs : cell . outputs ,
389- metadata : cell . metadata
390- } ) )
391- } ]
378+ this . _mainThreadNotebook . addNotebookDocument ( {
379+ viewType : document . viewType ,
380+ handle : document . handle ,
381+ uri : document . uri ,
382+ metadata : document . textModel . metadata ,
383+ versionId : document . textModel . versionId ,
384+ cells : document . textModel . cells . map ( cell => ( {
385+ handle : cell . handle ,
386+ uri : cell . uri ,
387+ source : cell . textBuffer . getLinesContent ( ) ,
388+ language : cell . language ,
389+ cellKind : cell . cellKind ,
390+ outputs : cell . outputs ,
391+ metadata : cell . metadata
392+ } ) ) ,
393+ attachedEditor : editorId ? {
394+ id : editorId ,
395+ selections : document . textModel . selections
396+ } : undefined
392397 } ) ;
393398
394399 return document . textModel ;
@@ -410,24 +415,25 @@ export class MainThreadNotebookController implements IMainNotebookController {
410415 document . textModel . insertTemplateCell ( mainCell ) ;
411416 }
412417
413- await this . _proxy . $acceptDocumentAndEditorsDelta ( {
414- addedDocuments : [ {
415- viewType : document . viewType ,
416- handle : document . handle ,
417- webviewId : document . webviewId ,
418- uri : document . uri ,
419- metadata : document . textModel . metadata ,
420- versionId : document . textModel . versionId ,
421- cells : document . textModel . cells . map ( cell => ( {
422- handle : cell . handle ,
423- uri : cell . uri ,
424- source : cell . textBuffer . getLinesContent ( ) ,
425- language : cell . language ,
426- cellKind : cell . cellKind ,
427- outputs : cell . outputs ,
428- metadata : cell . metadata
429- } ) )
430- } ]
418+ await this . _mainThreadNotebook . addNotebookDocument ( {
419+ viewType : document . viewType ,
420+ handle : document . handle ,
421+ uri : document . uri ,
422+ metadata : document . textModel . metadata ,
423+ versionId : document . textModel . versionId ,
424+ cells : document . textModel . cells . map ( cell => ( {
425+ handle : cell . handle ,
426+ uri : cell . uri ,
427+ source : cell . textBuffer . getLinesContent ( ) ,
428+ language : cell . language ,
429+ cellKind : cell . cellKind ,
430+ outputs : cell . outputs ,
431+ metadata : cell . metadata
432+ } ) ) ,
433+ attachedEditor : editorId ? {
434+ id : editorId ,
435+ selections : document . textModel . selections
436+ } : undefined
431437 } ) ;
432438
433439 this . _proxy . $acceptEditorPropertiesChanged ( uri , { selections : null , metadata : document . textModel . metadata } ) ;
0 commit comments