@@ -16,7 +16,7 @@ import { URI, UriComponents } from 'vs/base/common/uri';
1616import { IExtensionDescription } from 'vs/platform/extensions/common/extensions' ;
1717import * as files from 'vs/platform/files/common/files' ;
1818import { Cache } from 'vs/workbench/api/common/cache' ;
19- import { ExtHostNotebookShape , IMainContext , IModelAddedData , INotebookCellStatusBarListDto , INotebookDocumentsAndEditorsDelta , INotebookDocumentShowOptions , INotebookEditorAddData , MainContext , MainThreadNotebookDocumentsShape , MainThreadNotebookEditorsShape , MainThreadNotebookShape , NotebookDataDto } from 'vs/workbench/api/common/extHost.protocol' ;
19+ import { ExtHostNotebookShape , IMainContext , IModelAddedData , INotebookCellStatusBarListDto , INotebookDocumentsAndEditorsDelta , INotebookDocumentShowOptions , INotebookEditorAddData , INotebookPartialFileStatsWithMetadata , MainContext , MainThreadNotebookDocumentsShape , MainThreadNotebookEditorsShape , MainThreadNotebookShape , NotebookDataDto } from 'vs/workbench/api/common/extHost.protocol' ;
2020import { ApiCommand , ApiCommandArgument , ApiCommandResult , CommandsConverter , ExtHostCommands } from 'vs/workbench/api/common/extHostCommands' ;
2121import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments' ;
2222import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors' ;
@@ -29,8 +29,8 @@ import { ExtHostCell, ExtHostNotebookDocument } from './extHostNotebookDocument'
2929import { ExtHostNotebookEditor } from './extHostNotebookEditor' ;
3030import { onUnexpectedExternalError } from 'vs/base/common/errors' ;
3131import { IExtHostConsumerFileSystem } from 'vs/workbench/api/common/extHostFileSystemConsumer' ;
32- // import { filter } from 'vs/base/common/objects ';
33- // import { ExtHostFileSystem } from 'vs/workbench/api/ common/extHostFileSystem ';
32+ import { basename } from 'vs/base/common/resources ' ;
33+ import { filter } from 'vs/base/ common/objects ' ;
3434
3535
3636
@@ -268,14 +268,14 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
268268 // --- serialize/deserialize
269269
270270 private _handlePool = 0 ;
271- private readonly _notebookSerializer = new Map < number , vscode . NotebookSerializer > ( ) ;
271+ private readonly _notebookSerializer = new Map < number , { viewType : string ; serializer : vscode . NotebookSerializer ; options : vscode . NotebookDocumentContentOptions | undefined } > ( ) ;
272272
273273 registerNotebookSerializer ( extension : IExtensionDescription , viewType : string , serializer : vscode . NotebookSerializer , options ?: vscode . NotebookDocumentContentOptions , registration ?: vscode . NotebookRegistrationData ) : vscode . Disposable {
274274 if ( isFalsyOrWhitespace ( viewType ) ) {
275275 throw new Error ( `viewType cannot be empty or just whitespace` ) ;
276276 }
277277 const handle = this . _handlePool ++ ;
278- this . _notebookSerializer . set ( handle , serializer ) ;
278+ this . _notebookSerializer . set ( handle , { viewType , serializer, options } ) ;
279279 this . _notebookProxy . $registerNotebookSerializer (
280280 handle ,
281281 { id : extension . identifier , location : extension . extensionLocation } ,
@@ -293,7 +293,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
293293 if ( ! serializer ) {
294294 throw new Error ( 'NO serializer found' ) ;
295295 }
296- const data = await serializer . deserializeNotebook ( bytes . buffer , token ) ;
296+ const data = await serializer . serializer . deserializeNotebook ( bytes . buffer , token ) ;
297297 return new SerializableObjectWithBuffers ( typeConverters . NotebookData . from ( data ) ) ;
298298 }
299299
@@ -302,11 +302,11 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
302302 if ( ! serializer ) {
303303 throw new Error ( 'NO serializer found' ) ;
304304 }
305- const bytes = await serializer . serializeNotebook ( typeConverters . NotebookData . to ( data . value ) , token ) ;
305+ const bytes = await serializer . serializer . serializeNotebook ( typeConverters . NotebookData . to ( data . value ) , token ) ;
306306 return VSBuffer . wrap ( bytes ) ;
307307 }
308308
309- async $saveNotebook ( handle : number , uriComponents : UriComponents , versionId : number , options : files . IWriteFileOptions , token : CancellationToken ) : Promise < files . IStat > {
309+ async $saveNotebook ( handle : number , uriComponents : UriComponents , versionId : number , options : files . IWriteFileOptions , token : CancellationToken ) : Promise < INotebookPartialFileStatsWithMetadata > {
310310 const uri = URI . revive ( uriComponents ) ;
311311 const serializer = this . _notebookSerializer . get ( handle ) ;
312312 if ( ! serializer ) {
@@ -323,7 +323,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
323323 }
324324
325325 const data : vscode . NotebookData = {
326- metadata : document . apiNotebook . metadata , // filter(document.apiNotebook.metadata, key => !serializer.options.transientDocumentMetadata[key]),
326+ metadata : filter ( document . apiNotebook . metadata , key => ! ( serializer . options ? .transientDocumentMetadata ?? { } ) [ key ] ) ,
327327 cells : [ ] ,
328328 } ;
329329
@@ -333,23 +333,36 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
333333 cell . document . getText ( ) ,
334334 cell . document . languageId ,
335335 cell . mime ,
336- [ ...cell . outputs ] ,
336+ ! ( serializer . options ?. transientOutputs ) ? [ ...cell . outputs ] : [ ] ,
337337 cell . metadata ,
338338 cell . executionSummary
339339 ) ;
340340
341- // cellData.outputs = !serializer.options.transientOutputs ? cell.outputs : [];
342- // cellData.metadata = filter(cell.metadata, key => !serializer.options.transientCellMetadata[key]);
343-
341+ cellData . metadata = filter ( cell . metadata , key => ! ( serializer . options ?. transientCellMetadata ?? { } ) [ key ] ) ;
344342 data . cells . push ( cellData ) ;
345343 }
346344
347- const bytes = await serializer . serializeNotebook ( data , token ) ;
345+ const bytes = await serializer . serializer . serializeNotebook ( data , token ) ;
348346 await this . _extHostFileSystem . value . writeFile ( uri , bytes ) ;
347+ const stat = await this . _extHostFileSystem . value . stat ( uri ) ;
348+
349+ const fileStats = {
350+ name : basename ( uri ) , // providerExtUri.basename(resource)
351+ isFile : ( stat . type & files . FileType . File ) !== 0 ,
352+ isDirectory : ( stat . type & files . FileType . Directory ) !== 0 ,
353+ isSymbolicLink : ( stat . type & files . FileType . SymbolicLink ) !== 0 ,
354+ mtime : stat . mtime ,
355+ ctime : stat . ctime ,
356+ size : stat . size ,
357+ readonly : Boolean ( ( stat . permissions ?? 0 ) & files . FilePermission . Readonly ) || ! this . _extHostFileSystem . value . isWritableFileSystem ( uri . scheme ) ,
358+ locked : Boolean ( ( stat . permissions ?? 0 ) & files . FilePermission . Locked ) ,
359+ etag : files . etag ( { mtime : stat . mtime , size : stat . size } ) ,
360+ children : undefined
361+ } ;
349362
350- const stats = await this . _extHostFileSystem . value . stat ( uri ) ;
351- return stats ;
363+ return fileStats ;
352364 }
365+
353366 // --- open, save, saveAs, backup
354367
355368
0 commit comments