mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-25 01:25:36 -05:00
Add localContentManger and dummy sessionManager (#3130)
* - keyboard binding to arrow keys - toggle markdown editor by double click * Added localContentManger and dummpy sessionManager
This commit is contained in:
32
src/sql/services/notebook/localContentManager.ts
Normal file
32
src/sql/services/notebook/localContentManager.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
import { nb } from 'sqlops';
|
||||
|
||||
import * as json from 'vs/base/common/json';
|
||||
import * as pfs from 'vs/base/node/pfs';
|
||||
|
||||
import ContentManager = nb.ContentManager;
|
||||
import INotebook = nb.INotebook;
|
||||
|
||||
export class LocalContentManager implements ContentManager {
|
||||
public async getNotebookContents(path: string): Promise<INotebook> {
|
||||
if (!path) {
|
||||
return undefined;
|
||||
}
|
||||
// Note: intentionally letting caller handle exceptions
|
||||
let notebookFileBuffer = await pfs.readFile(path);
|
||||
return <INotebook>json.parse(notebookFileBuffer.toString());
|
||||
}
|
||||
|
||||
public async save(path: string, notebook: INotebook): Promise<INotebook> {
|
||||
// Convert to JSON with pretty-print functionality
|
||||
let contents = JSON.stringify(notebook, undefined, ' ');
|
||||
await pfs.writeFile(path, contents);
|
||||
return notebook;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,8 +7,11 @@
|
||||
|
||||
import { nb } from 'sqlops';
|
||||
import * as nls from 'vs/nls';
|
||||
import { INotebookService, INotebookManager, INotebookProvider } from 'sql/services/notebook/notebookService';
|
||||
import { INotebookService, INotebookManager, INotebookProvider, DEFAULT_NOTEBOOK_PROVIDER } from 'sql/services/notebook/notebookService';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import { LocalContentManager } from 'sql/services/notebook/localContentManager';
|
||||
import { session } from 'electron';
|
||||
import { SessionManager } from 'sql/services/notebook/sessionManager';
|
||||
|
||||
export class NotebookService implements INotebookService {
|
||||
_serviceBrand: any;
|
||||
@@ -16,6 +19,11 @@ export class NotebookService implements INotebookService {
|
||||
private _providers: Map<string, INotebookProvider> = new Map();
|
||||
private _managers: Map<URI, INotebookManager> = new Map();
|
||||
|
||||
constructor() {
|
||||
let defaultProvider = new BuiltinProvider();
|
||||
this.registerProvider(defaultProvider.providerId, defaultProvider);
|
||||
}
|
||||
|
||||
registerProvider(providerId: string, provider: INotebookProvider): void {
|
||||
this._providers.set(providerId, provider);
|
||||
}
|
||||
@@ -57,4 +65,48 @@ export class NotebookService implements INotebookService {
|
||||
|
||||
return op(provider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class BuiltinProvider implements INotebookProvider {
|
||||
private manager: BuiltInNotebookManager;
|
||||
|
||||
constructor() {
|
||||
this.manager = new BuiltInNotebookManager();
|
||||
}
|
||||
public get providerId(): string {
|
||||
return DEFAULT_NOTEBOOK_PROVIDER;
|
||||
}
|
||||
|
||||
getNotebookManager(notebookUri: URI): Thenable<INotebookManager> {
|
||||
return Promise.resolve(this.manager);
|
||||
}
|
||||
handleNotebookClosed(notebookUri: URI): void {
|
||||
// No-op
|
||||
}
|
||||
}
|
||||
|
||||
export class BuiltInNotebookManager implements INotebookManager {
|
||||
private _contentManager: nb.ContentManager;
|
||||
private _sessionManager: nb.SessionManager;
|
||||
|
||||
constructor() {
|
||||
this._contentManager = new LocalContentManager();
|
||||
this._sessionManager = new SessionManager();
|
||||
}
|
||||
public get providerId(): string {
|
||||
return DEFAULT_NOTEBOOK_PROVIDER;
|
||||
}
|
||||
|
||||
public get contentManager(): nb.ContentManager {
|
||||
return this._contentManager;
|
||||
}
|
||||
|
||||
public get serverManager(): nb.ServerManager {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
public get sessionManager(): nb.SessionManager {
|
||||
return this._sessionManager;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
31
src/sql/services/notebook/sessionManager.ts
Normal file
31
src/sql/services/notebook/sessionManager.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
import { nb } from 'sqlops';
|
||||
import { Session } from 'electron';
|
||||
|
||||
export class SessionManager implements nb.SessionManager {
|
||||
private _sessionManager: nb.SessionManager;
|
||||
|
||||
constructor() {
|
||||
|
||||
}
|
||||
public get isReady(): boolean {
|
||||
return this._sessionManager.isReady;
|
||||
}
|
||||
|
||||
public get ready(): Thenable<void> {
|
||||
return this._sessionManager.ready;
|
||||
}
|
||||
public get specs(): nb.IAllKernels {
|
||||
return this._sessionManager.specs;
|
||||
}
|
||||
|
||||
startNew(options: nb.ISessionOptions): Thenable<nb.ISession> {
|
||||
return this._sessionManager.startNew(options);
|
||||
}
|
||||
|
||||
shutdown(id: string): Thenable<void> {
|
||||
return this.shutdown(id);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user