@@ -25,6 +25,7 @@ import { asWebviewUri, WebviewInitData } from 'vs/workbench/api/common/shared/we
2525import { CellEditType , CellOutputKind , diff , ICellDeleteEdit , ICellEditOperation , ICellInsertEdit , IMainCellDto , INotebookDisplayOrder , INotebookEditData , INotebookKernelInfoDto2 , IOutputRenderRequest , IOutputRenderResponse , IOutputRenderResponseCellInfo , IOutputRenderResponseOutputInfo , IProcessedOutput , IRawOutput , NotebookCellMetadata , NotebookCellsChangedEvent , NotebookCellsChangeType , NotebookCellsSplice2 , NotebookDataDto , notebookDocumentMetadataDefaults } from 'vs/workbench/contrib/notebook/common/notebookCommon' ;
2626import * as vscode from 'vscode' ;
2727import { Cache } from './cache' ;
28+ import { ResourceMap } from 'vs/base/common/map' ;
2829
2930
3031interface IObservable < T > {
@@ -881,8 +882,8 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
881882 private readonly _notebookContentProviders = new Map < string , { readonly provider : vscode . NotebookContentProvider , readonly extension : IExtensionDescription ; } > ( ) ;
882883 private readonly _notebookKernels = new Map < string , { readonly kernel : vscode . NotebookKernel , readonly extension : IExtensionDescription ; } > ( ) ;
883884 private readonly _notebookKernelProviders = new Map < number , ExtHostNotebookKernelProviderAdapter > ( ) ;
884- private readonly _documents = new Map < string , ExtHostNotebookDocument > ( ) ;
885- private readonly _unInitializedDocuments = new Map < string , ExtHostNotebookDocument > ( ) ;
885+ private readonly _documents = new ResourceMap < ExtHostNotebookDocument > ( ) ;
886+ private readonly _unInitializedDocuments = new ResourceMap < ExtHostNotebookDocument > ( ) ;
886887 private readonly _editors = new Map < string , { editor : ExtHostNotebookEditor ; } > ( ) ;
887888 private readonly _webviewComm = new Map < string , ExtHostWebviewCommWrapper > ( ) ;
888889 private readonly _notebookOutputRenderers = new Map < string , ExtHostNotebookOutputRenderer > ( ) ;
@@ -980,7 +981,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
980981 throw new Error ( `Notebook renderer for '${ id } ' is not registered` ) ;
981982 }
982983
983- const document = this . _documents . get ( URI . revive ( uriComponents ) . toString ( ) ) ;
984+ const document = this . _documents . get ( URI . revive ( uriComponents ) ) ;
984985
985986 if ( ! document ) {
986987 return ;
@@ -1018,7 +1019,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
10181019 throw new Error ( `Notebook renderer for '${ id } ' is not registered` ) ;
10191020 }
10201021
1021- const document = this . _documents . get ( URI . revive ( uriComponents ) . toString ( ) ) ;
1022+ const document = this . _documents . get ( URI . revive ( uriComponents ) ) ;
10221023
10231024 if ( ! document ) {
10241025 return ;
@@ -1076,7 +1077,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
10761077
10771078 const listener = provider . onDidChangeNotebook
10781079 ? provider . onDidChangeNotebook ( e => {
1079- const document = this . _documents . get ( URI . revive ( e . document . uri ) . toString ( ) ) ;
1080+ const document = this . _documents . get ( URI . revive ( e . document . uri ) ) ;
10801081
10811082 if ( ! document ) {
10821083 throw new Error ( `Notebook document ${ e . document . uri . toString ( ) } not found` ) ;
@@ -1120,7 +1121,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
11201121 }
11211122
11221123 private _withAdapter < T > ( handle : number , uri : UriComponents , callback : ( adapter : ExtHostNotebookKernelProviderAdapter , document : ExtHostNotebookDocument ) => Promise < T > ) {
1123- const document = this . _documents . get ( URI . revive ( uri ) . toString ( ) ) ;
1124+ const document = this . _documents . get ( URI . revive ( uri ) ) ;
11241125
11251126 if ( ! document ) {
11261127 return [ ] ;
@@ -1169,57 +1170,56 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
11691170 async $resolveNotebookData ( viewType : string , uri : UriComponents , backupId ?: string ) : Promise < NotebookDataDto | undefined > {
11701171 const provider = this . _notebookContentProviders . get ( viewType ) ;
11711172 const revivedUri = URI . revive ( uri ) ;
1173+ if ( ! provider ) {
1174+ return ;
1175+ }
11721176
1173- if ( provider ) {
1174- let storageRoot : URI | undefined ;
1175- if ( this . _extensionStoragePaths ) {
1176- storageRoot = this . _extensionStoragePaths . workspaceValue ( provider . extension ) ?? this . _extensionStoragePaths . globalValue ( provider . extension ) ;
1177- }
1177+ let storageRoot : URI | undefined ;
1178+ if ( this . _extensionStoragePaths ) {
1179+ storageRoot = this . _extensionStoragePaths . workspaceValue ( provider . extension ) ?? this . _extensionStoragePaths . globalValue ( provider . extension ) ;
1180+ }
11781181
1179- let document = this . _documents . get ( URI . revive ( uri ) . toString ( ) ) ;
1180-
1181- if ( ! document ) {
1182- const that = this ;
1183- document = this . _unInitializedDocuments . get ( revivedUri . toString ( ) ) ?? new ExtHostNotebookDocument ( this . _proxy , this . _documentsAndEditors , {
1184- emitModelChange ( event : vscode . NotebookCellsChangeEvent ) : void {
1185- that . _onDidChangeNotebookCells . fire ( event ) ;
1186- } ,
1187- emitCellOutputsChange ( event : vscode . NotebookCellOutputsChangeEvent ) : void {
1188- that . _onDidChangeCellOutputs . fire ( event ) ;
1189- } ,
1190- emitCellLanguageChange ( event : vscode . NotebookCellLanguageChangeEvent ) : void {
1191- that . _onDidChangeCellLanguage . fire ( event ) ;
1192- } ,
1193- emitCellMetadataChange ( event : vscode . NotebookCellMetadataChangeEvent ) : void {
1194- that . _onDidChangeCellMetadata . fire ( event ) ;
1195- } ,
1196- } , viewType , revivedUri , this , storageRoot ) ;
1197- this . _unInitializedDocuments . set ( revivedUri . toString ( ) , document ) ;
1198- }
1182+ let document = this . _documents . get ( revivedUri ) ;
11991183
1200- const rawCells = await provider . provider . openNotebook ( URI . revive ( uri ) , { backupId } ) ;
1201- const dto = {
1202- metadata : {
1203- ... notebookDocumentMetadataDefaults ,
1204- ... rawCells . metadata
1184+ if ( ! document ) {
1185+ const that = this ;
1186+ document = this . _unInitializedDocuments . get ( revivedUri ) ?? new ExtHostNotebookDocument ( this . _proxy , this . _documentsAndEditors , {
1187+ emitModelChange ( event : vscode . NotebookCellsChangeEvent ) : void {
1188+ that . _onDidChangeNotebookCells . fire ( event ) ;
12051189 } ,
1206- languages : rawCells . languages ,
1207- cells : rawCells . cells . map ( cell => ( {
1208- ...cell ,
1209- outputs : cell . outputs . map ( o => addIdToOutput ( o ) )
1210- } ) ) ,
1211- } ;
1212-
1213- return dto ;
1190+ emitCellOutputsChange ( event : vscode . NotebookCellOutputsChangeEvent ) : void {
1191+ that . _onDidChangeCellOutputs . fire ( event ) ;
1192+ } ,
1193+ emitCellLanguageChange ( event : vscode . NotebookCellLanguageChangeEvent ) : void {
1194+ that . _onDidChangeCellLanguage . fire ( event ) ;
1195+ } ,
1196+ emitCellMetadataChange ( event : vscode . NotebookCellMetadataChangeEvent ) : void {
1197+ that . _onDidChangeCellMetadata . fire ( event ) ;
1198+ } ,
1199+ } , viewType , revivedUri , this , storageRoot ) ;
1200+ this . _unInitializedDocuments . set ( revivedUri , document ) ;
12141201 }
12151202
1216- return ;
1203+ const rawCells = await provider . provider . openNotebook ( URI . revive ( uri ) , { backupId } ) ;
1204+ const dto = {
1205+ metadata : {
1206+ ...notebookDocumentMetadataDefaults ,
1207+ ...rawCells . metadata
1208+ } ,
1209+ languages : rawCells . languages ,
1210+ cells : rawCells . cells . map ( cell => ( {
1211+ ...cell ,
1212+ outputs : cell . outputs . map ( o => addIdToOutput ( o ) )
1213+ } ) ) ,
1214+ } ;
1215+
1216+ return dto ;
12171217 }
12181218
12191219 async $resolveNotebookEditor ( viewType : string , uri : UriComponents , editorId : string ) : Promise < void > {
12201220 const provider = this . _notebookContentProviders . get ( viewType ) ;
12211221 const revivedUri = URI . revive ( uri ) ;
1222- const document = this . _documents . get ( revivedUri . toString ( ) ) ;
1222+ const document = this . _documents . get ( revivedUri ) ;
12231223 if ( ! document || ! provider ) {
12241224 return ;
12251225 }
@@ -1258,7 +1258,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
12581258 }
12591259
12601260 async $executeNotebookByAttachedKernel ( viewType : string , uri : UriComponents , cellHandle : number | undefined ) : Promise < void > {
1261- const document = this . _documents . get ( URI . revive ( uri ) . toString ( ) ) ;
1261+ const document = this . _documents . get ( URI . revive ( uri ) ) ;
12621262
12631263 if ( ! document ) {
12641264 return ;
@@ -1279,7 +1279,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
12791279 }
12801280
12811281 async $cancelNotebookByAttachedKernel ( viewType : string , uri : UriComponents , cellHandle : number | undefined ) : Promise < void > {
1282- const document = this . _documents . get ( URI . revive ( uri ) . toString ( ) ) ;
1282+ const document = this . _documents . get ( URI . revive ( uri ) ) ;
12831283
12841284 if ( ! document ) {
12851285 return ;
@@ -1316,7 +1316,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
13161316 }
13171317
13181318 async $executeNotebook2 ( kernelId : string , viewType : string , uri : UriComponents , cellHandle : number | undefined ) : Promise < void > {
1319- const document = this . _documents . get ( URI . revive ( uri ) . toString ( ) ) ;
1319+ const document = this . _documents . get ( URI . revive ( uri ) ) ;
13201320
13211321 if ( ! document || document . viewType !== viewType ) {
13221322 return ;
@@ -1338,7 +1338,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
13381338 }
13391339
13401340 async $saveNotebook ( viewType : string , uri : UriComponents , token : CancellationToken ) : Promise < boolean > {
1341- const document = this . _documents . get ( URI . revive ( uri ) . toString ( ) ) ;
1341+ const document = this . _documents . get ( URI . revive ( uri ) ) ;
13421342 if ( ! document ) {
13431343 return false ;
13441344 }
@@ -1352,7 +1352,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
13521352 }
13531353
13541354 async $saveNotebookAs ( viewType : string , uri : UriComponents , target : UriComponents , token : CancellationToken ) : Promise < boolean > {
1355- const document = this . _documents . get ( URI . revive ( uri ) . toString ( ) ) ;
1355+ const document = this . _documents . get ( URI . revive ( uri ) ) ;
13561356 if ( ! document ) {
13571357 return false ;
13581358 }
@@ -1366,7 +1366,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
13661366 }
13671367
13681368 async $undoNotebook ( viewType : string , uri : UriComponents , editId : number , isDirty : boolean ) : Promise < void > {
1369- const document = this . _documents . get ( URI . revive ( uri ) . toString ( ) ) ;
1369+ const document = this . _documents . get ( URI . revive ( uri ) ) ;
13701370 if ( ! document ) {
13711371 return ;
13721372 }
@@ -1376,7 +1376,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
13761376 }
13771377
13781378 async $redoNotebook ( viewType : string , uri : UriComponents , editId : number , isDirty : boolean ) : Promise < void > {
1379- const document = this . _documents . get ( URI . revive ( uri ) . toString ( ) ) ;
1379+ const document = this . _documents . get ( URI . revive ( uri ) ) ;
13801380 if ( ! document ) {
13811381 return ;
13821382 }
@@ -1386,7 +1386,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
13861386
13871387
13881388 async $backup ( viewType : string , uri : UriComponents , cancellation : CancellationToken ) : Promise < string | undefined > {
1389- const document = this . _documents . get ( URI . revive ( uri ) . toString ( ) ) ;
1389+ const document = this . _documents . get ( URI . revive ( uri ) ) ;
13901390 const provider = this . _notebookContentProviders . get ( viewType ) ;
13911391
13921392 if ( document && provider && provider . provider . backupNotebook ) {
@@ -1435,15 +1435,15 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
14351435
14361436 $acceptModelChanged ( uriComponents : UriComponents , event : NotebookCellsChangedEvent ) : void {
14371437
1438- const document = this . _documents . get ( URI . revive ( uriComponents ) . toString ( ) ) ;
1438+ const document = this . _documents . get ( URI . revive ( uriComponents ) ) ;
14391439
14401440 if ( document ) {
14411441 document . acceptModelChanged ( event ) ;
14421442 }
14431443 }
14441444
14451445 public $acceptModelSaved ( uriComponents : UriComponents ) : void {
1446- const document = this . _documents . get ( URI . revive ( uriComponents ) . toString ( ) ) ;
1446+ const document = this . _documents . get ( URI . revive ( uriComponents ) ) ;
14471447 if ( document ) {
14481448 // this.$acceptDirtyStateChanged(uriComponents, false);
14491449 this . _onDidSaveNotebookDocument . fire ( document ) ;
@@ -1519,18 +1519,17 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
15191519 if ( delta . removedDocuments ) {
15201520 delta . removedDocuments . forEach ( ( uri ) => {
15211521 const revivedUri = URI . revive ( uri ) ;
1522- const revivedUriStr = revivedUri . toString ( ) ;
1523- const document = this . _documents . get ( revivedUriStr ) ;
1522+ const document = this . _documents . get ( revivedUri ) ;
15241523
15251524 if ( document ) {
15261525 document . dispose ( ) ;
1527- this . _documents . delete ( revivedUriStr ) ;
1526+ this . _documents . delete ( revivedUri ) ;
15281527 this . _documentsAndEditors . $acceptDocumentsAndEditorsDelta ( { removedDocuments : document . cells . map ( cell => cell . uri ) } ) ;
15291528 this . _onDidCloseNotebookDocument . fire ( document ) ;
15301529 }
15311530
15321531 [ ...this . _editors . values ( ) ] . forEach ( ( e ) => {
1533- if ( e . editor . uri . toString ( ) === revivedUriStr ) {
1532+ if ( e . editor . uri . toString ( ) === revivedUri . toString ( ) ) {
15341533 e . editor . dispose ( ) ;
15351534 this . _editors . delete ( e . editor . id ) ;
15361535 editorChanged = true ;
@@ -1545,18 +1544,17 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
15451544
15461545 delta . addedDocuments . forEach ( modelData => {
15471546 const revivedUri = URI . revive ( modelData . uri ) ;
1548- const revivedUriStr = revivedUri . toString ( ) ;
15491547 const viewType = modelData . viewType ;
15501548 const entry = this . _notebookContentProviders . get ( viewType ) ;
15511549 let storageRoot : URI | undefined ;
15521550 if ( entry && this . _extensionStoragePaths ) {
15531551 storageRoot = this . _extensionStoragePaths . workspaceValue ( entry . extension ) ?? this . _extensionStoragePaths . globalValue ( entry . extension ) ;
15541552 }
15551553
1556- if ( ! this . _documents . has ( revivedUriStr ) ) {
1554+ if ( ! this . _documents . has ( revivedUri ) ) {
15571555 const that = this ;
15581556
1559- const document = this . _unInitializedDocuments . get ( revivedUriStr ) ?? new ExtHostNotebookDocument ( this . _proxy , this . _documentsAndEditors , {
1557+ const document = this . _unInitializedDocuments . get ( revivedUri ) ?? new ExtHostNotebookDocument ( this . _proxy , this . _documentsAndEditors , {
15601558 emitModelChange ( event : vscode . NotebookCellsChangeEvent ) : void {
15611559 that . _onDidChangeNotebookCells . fire ( event ) ;
15621560 } ,
@@ -1571,7 +1569,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
15711569 }
15721570 } , viewType , revivedUri , this , storageRoot ) ;
15731571
1574- this . _unInitializedDocuments . delete ( revivedUriStr ) ;
1572+ this . _unInitializedDocuments . delete ( revivedUri ) ;
15751573 if ( modelData . metadata ) {
15761574 document . metadata = {
15771575 ...notebookDocumentMetadataDefaults ,
@@ -1592,8 +1590,8 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
15921590 // add cell document as vscode.TextDocument
15931591 addedCellDocuments . push ( ...modelData . cells . map ( ExtHostCell . asModelAddData ) ) ;
15941592
1595- this . _documents . get ( revivedUriStr ) ?. dispose ( ) ;
1596- this . _documents . set ( revivedUriStr , document ) ;
1593+ this . _documents . get ( revivedUri ) ?. dispose ( ) ;
1594+ this . _documents . set ( revivedUri , document ) ;
15971595
15981596 // create editor if populated
15991597 if ( modelData . attachedEditor ) {
@@ -1606,7 +1604,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
16061604 addedDocuments : addedCellDocuments
16071605 } ) ;
16081606
1609- const document = this . _documents . get ( revivedUriStr ) ! ;
1607+ const document = this . _documents . get ( revivedUri ) ! ;
16101608 this . _onDidOpenNotebookDocument . fire ( document ) ;
16111609 } ) ;
16121610 }
@@ -1618,7 +1616,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape, ExtHostN
16181616 }
16191617
16201618 const revivedUri = URI . revive ( editorModelData . documentUri ) ;
1621- const document = this . _documents . get ( revivedUri . toString ( ) ) ;
1619+ const document = this . _documents . get ( revivedUri ) ;
16221620
16231621 if ( document ) {
16241622 this . _createExtHostEditor ( document , editorModelData . id , editorModelData . selections ) ;
0 commit comments