Add option to use notebook json contents instead of file string when creating a notebook. (#18972)

This commit is contained in:
Cory Rivera
2022-04-08 16:39:14 -07:00
committed by GitHub
parent 828c6760e2
commit c2cc32a4a0
4 changed files with 44 additions and 19 deletions

View File

@@ -222,6 +222,7 @@ export abstract class NotebookInput extends EditorInput implements INotebookInpu
private _providers: string[];
private _standardKernels: IStandardKernelWithProvider[];
private _connectionProfile: IConnectionProfile;
private _notebookContents: azdata.nb.INotebookContents;
private _defaultKernel: azdata.nb.IKernelSpec;
public hasBootstrapped = false;
// Holds the HTML content for the editor when the editor discards this input and loads another
@@ -283,7 +284,7 @@ export abstract class NotebookInput extends EditorInput implements INotebookInpu
public get contentLoader(): IContentLoader {
if (!this._contentLoader) {
let contentManager = this.instantiationService.createInstance(LocalContentManager);
this._contentLoader = this.instantiationService.createInstance(NotebookEditorContentLoader, this, contentManager);
this._contentLoader = this.instantiationService.createInstance(NotebookEditorContentLoader, this, contentManager, this._notebookContents);
}
return this._contentLoader;
}
@@ -319,6 +320,11 @@ export abstract class NotebookInput extends EditorInput implements INotebookInpu
return this._connectionProfile;
}
public setNotebookContents(value: azdata.nb.INotebookContents) {
this._notebookContents = value;
(this.contentLoader as NotebookEditorContentLoader).notebookContents = value;
}
public get standardKernels(): IStandardKernelWithProvider[] {
return this._standardKernels;
}
@@ -461,7 +467,7 @@ export abstract class NotebookInput extends EditorInput implements INotebookInpu
this._standardKernels.push(...standardKernels);
}
let serializationProvider = await this.notebookService.getOrCreateSerializationManager(this._providerId, this._resource);
this._contentLoader = this.instantiationService.createInstance(NotebookEditorContentLoader, this, serializationProvider.contentManager);
this._contentLoader = this.instantiationService.createInstance(NotebookEditorContentLoader, this, serializationProvider.contentManager, this._notebookContents);
}
}
@@ -541,12 +547,18 @@ export abstract class NotebookInput extends EditorInput implements INotebookInpu
export class NotebookEditorContentLoader implements IContentLoader {
constructor(
private notebookInput: NotebookInput,
private contentManager: azdata.nb.ContentManager) {
private contentManager: azdata.nb.ContentManager,
public notebookContents: azdata.nb.INotebookContents | undefined) {
}
async loadContent(): Promise<azdata.nb.INotebookContents> {
let notebookEditorModel = await this.notebookInput.resolve();
let notebookContents = await this.contentManager.deserializeNotebook(notebookEditorModel.contentString);
let notebookContents: azdata.nb.INotebookContents;
if (this.notebookContents) {
notebookContents = this.notebookContents;
} else {
let notebookEditorModel = await this.notebookInput.resolve();
notebookContents = await this.contentManager.deserializeNotebook(notebookEditorModel.contentString);
}
// Special case .NET Interactive kernel spec to handle inconsistencies between notebook providers and jupyter kernel specs
if (notebookContents.metadata?.kernelspec?.display_name?.startsWith(DotnetInteractiveJupyterLabelPrefix)) {