@@ -14,6 +14,7 @@ import { isFalsyOrWhitespace } from 'vs/base/common/strings';
1414import { assertIsDefined } from 'vs/base/common/types' ;
1515import { URI , UriComponents } from 'vs/base/common/uri' ;
1616import { IExtensionDescription } from 'vs/platform/extensions/common/extensions' ;
17+ import * as files from 'vs/platform/files/common/files' ;
1718import { Cache } from 'vs/workbench/api/common/cache' ;
1819import { ExtHostNotebookShape , IMainContext , IModelAddedData , INotebookCellStatusBarListDto , INotebookDocumentsAndEditorsDelta , INotebookDocumentShowOptions , INotebookEditorAddData , MainContext , MainThreadNotebookDocumentsShape , MainThreadNotebookEditorsShape , MainThreadNotebookShape , NotebookDataDto } from 'vs/workbench/api/common/extHost.protocol' ;
1920import { ApiCommand , ApiCommandArgument , ApiCommandResult , CommandsConverter , ExtHostCommands } from 'vs/workbench/api/common/extHostCommands' ;
@@ -27,6 +28,9 @@ import type * as vscode from 'vscode';
2728import { ExtHostCell , ExtHostNotebookDocument } from './extHostNotebookDocument' ;
2829import { ExtHostNotebookEditor } from './extHostNotebookEditor' ;
2930import { onUnexpectedExternalError } from 'vs/base/common/errors' ;
31+ import { IExtHostConsumerFileSystem } from 'vs/workbench/api/common/extHostFileSystemConsumer' ;
32+ // import { filter } from 'vs/base/common/objects';
33+ // import { ExtHostFileSystem } from 'vs/workbench/api/common/extHostFileSystem';
3034
3135
3236
@@ -69,6 +73,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
6973 commands : ExtHostCommands ,
7074 private _textDocumentsAndEditors : ExtHostDocumentsAndEditors ,
7175 private _textDocuments : ExtHostDocuments ,
76+ private _extHostFileSystem : IExtHostConsumerFileSystem
7277 ) {
7378 this . _notebookProxy = mainContext . getProxy ( MainContext . MainThreadNotebook ) ;
7479 this . _notebookDocumentsProxy = mainContext . getProxy ( MainContext . MainThreadNotebookDocuments ) ;
@@ -301,6 +306,50 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
301306 return VSBuffer . wrap ( bytes ) ;
302307 }
303308
309+ async $saveNotebook ( handle : number , uriComponents : UriComponents , versionId : number , options : files . IWriteFileOptions , token : CancellationToken ) : Promise < files . IStat > {
310+ const uri = URI . revive ( uriComponents ) ;
311+ const serializer = this . _notebookSerializer . get ( handle ) ;
312+ if ( ! serializer ) {
313+ throw new Error ( 'NO serializer found' ) ;
314+ }
315+
316+ const document = this . _documents . get ( uri ) ;
317+ if ( ! document ) {
318+ throw new Error ( 'Document NOT found' ) ;
319+ }
320+
321+ if ( document . versionId !== versionId ) {
322+ throw new Error ( 'Document version mismatch' ) ;
323+ }
324+
325+ const data : vscode . NotebookData = {
326+ metadata : document . apiNotebook . metadata , // filter(document.apiNotebook.metadata, key => !serializer.options.transientDocumentMetadata[key]),
327+ cells : [ ] ,
328+ } ;
329+
330+ for ( const cell of document . apiNotebook . getCells ( ) ) {
331+ const cellData = new extHostTypes . NotebookCellData (
332+ cell . kind ,
333+ cell . document . getText ( ) ,
334+ cell . document . languageId ,
335+ cell . mime ,
336+ [ ...cell . outputs ] ,
337+ cell . metadata ,
338+ cell . executionSummary
339+ ) ;
340+
341+ // cellData.outputs = !serializer.options.transientOutputs ? cell.outputs : [];
342+ // cellData.metadata = filter(cell.metadata, key => !serializer.options.transientCellMetadata[key]);
343+
344+ data . cells . push ( cellData ) ;
345+ }
346+
347+ const bytes = await serializer . serializeNotebook ( data , token ) ;
348+ await this . _extHostFileSystem . value . writeFile ( uri , bytes ) ;
349+
350+ const stats = await this . _extHostFileSystem . value . stat ( uri ) ;
351+ return stats ;
352+ }
304353 // --- open, save, saveAs, backup
305354
306355
0 commit comments