Begin defining Extension-based Notebook Provider (#3172)

Implements provider contribution in the MainThreadNotebook, with matching function calls in the ExtHostNotebook class. This will allow us to proxy through notebook providers (specifically, creation of a notebook manager with required content, server managers) from an extension up through to the main process.

Implemented in this PR:
- Callthroughs for content and server manager APIs
- Very basic unit tests covering provider & manager registration

Not implemented:
- Fuller unit tests on the specific callthrough methods for content & server manager.
- Contribution point needed to test this (so we can actually pass through the extension's existing Notebook implementation)
This commit is contained in:
Kevin Cunnane
2018-11-08 13:06:40 -08:00
committed by GitHub
parent 71c14a0837
commit 9765269d27
14 changed files with 597 additions and 49 deletions

View File

@@ -34,7 +34,7 @@ export class ClientSession implements IClientSession {
private _iopubMessageEmitter = new Emitter<nb.IMessage>();
private _unhandledMessageEmitter = new Emitter<nb.IMessage>();
private _propertyChangedEmitter = new Emitter<'path' | 'name' | 'type'>();
private _path: string;
private _notebookUri: URI;
private _type: string;
private _name: string;
private _isReady: boolean;
@@ -53,7 +53,7 @@ export class ClientSession implements IClientSession {
private _kernelConfigActions: ((kernelName: string) => Promise<any>)[] = [];
constructor(private options: IClientSessionOptions) {
this._path = options.path;
this._notebookUri = options.notebookUri;
this.notebookManager = options.notebookManager;
this._isReady = false;
this._ready = new Deferred<void>();
@@ -104,8 +104,9 @@ export class ClientSession implements IClientSession {
private async startSessionInstance(kernelName: string): Promise<void> {
let session: nb.ISession;
try {
// TODO #3164 should use URI instead of path for startNew
session = await this.notebookManager.sessionManager.startNew({
path: this.path,
path: this.notebookUri.fsPath,
kernelName: kernelName
// TODO add kernel name if saved in the document
});
@@ -115,7 +116,7 @@ export class ClientSession implements IClientSession {
if (err && err.response && err.response.status === 501) {
this.options.notificationService.warn(nls.localize('sparkKernelRequiresConnection', 'Kernel {0} was not found. The default kernel will be used instead.', kernelName));
session = await this.notebookManager.sessionManager.startNew({
path: this.path,
path: this.notebookUri.fsPath,
kernelName: undefined
});
} else {
@@ -169,8 +170,8 @@ export class ClientSession implements IClientSession {
public get kernel(): nb.IKernel | null {
return this._session ? this._session.kernel : undefined;
}
public get path(): string {
return this._path;
public get notebookUri(): URI {
return this._notebookUri;
}
public get name(): string {
return this._name;

View File

@@ -21,7 +21,7 @@ import { NotebookConnection } from 'sql/parts/notebook/models/notebookConnection
import { IConnectionManagementService } from 'sql/parts/connection/common/connectionManagement';
export interface IClientSessionOptions {
path: string;
notebookUri: URI;
notebookManager: INotebookManager;
notificationService: INotificationService;
}
@@ -73,7 +73,7 @@ export interface IClientSession extends IDisposable {
/**
* The current path associated with the client session.
*/
readonly path: string;
readonly notebookUri: URI;
/**
* The current name associated with the client session.
@@ -354,7 +354,7 @@ export interface INotebookModelOptions {
/**
* Path to the local or remote notebook
*/
path: string;
notebookUri: URI;
/**
* Factory for creating cells and client sessions

View File

@@ -81,7 +81,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
constructor(private notebookOptions: INotebookModelOptions, startSessionImmediately?: boolean, private connectionProfile?: IConnectionProfile) {
super();
if (!notebookOptions || !notebookOptions.path || !notebookOptions.notebookManager) {
if (!notebookOptions || !notebookOptions.notebookUri || !notebookOptions.notebookManager) {
throw new Error('path or notebook service not defined');
}
if (startSessionImmediately) {
@@ -183,7 +183,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
public async requestModelLoad(isTrusted: boolean = false): Promise<void> {
try {
this._trustedMode = isTrusted;
let contents = await this.notebookManager.contentManager.getNotebookContents(this.notebookOptions.path);
let contents = await this.notebookManager.contentManager.getNotebookContents(this.notebookOptions.notebookUri);
let factory = this.notebookOptions.factory;
// if cells already exist, create them with language info (if it is saved)
this._cells = undefined;
@@ -248,7 +248,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
public backgroundStartSession(): void {
this._clientSession = this.notebookOptions.factory.createClientSession({
path: this.notebookOptions.path,
notebookUri: this.notebookOptions.notebookUri,
notebookManager: this.notebookManager,
notificationService: this.notebookOptions.notificationService
});
@@ -416,7 +416,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
if (!notebook) {
return false;
}
await this.notebookManager.contentManager.save(this.notebookOptions.path, notebook);
await this.notebookManager.contentManager.save(this.notebookOptions.notebookUri, notebook);
this._contentChangedEmitter.fire({
changeType: NotebookChangeType.DirtyStateChanged,
isDirty: false