refactor notebook to be fileservice based (#6459)

This commit is contained in:
Anthony Dresser
2019-07-26 22:19:13 -07:00
committed by GitHub
parent 8e40aa3306
commit 371504358d
80 changed files with 192 additions and 175 deletions

View File

@@ -8,19 +8,22 @@
import { nb } from 'azdata';
import * as json from 'vs/base/common/json';
import * as pfs from 'vs/base/node/pfs';
import { URI } from 'vs/base/common/uri';
import { localize } from 'vs/nls';
import { IFileService } from 'vs/platform/files/common/files';
import { JSONObject } from 'sql/workbench/parts/notebook/common/models/jsonext';
import { OutputTypes } from 'sql/workbench/parts/notebook/common/models/contracts';
import { nbversion } from 'sql/workbench/parts/notebook/common/models/notebookConstants';
import { nbformat } from 'sql/workbench/parts/notebook/common/models/nbformat';
import { VSBuffer } from 'vs/base/common/buffer';
type MimeBundle = { [key: string]: string | string[] | undefined };
export class LocalContentManager implements nb.ContentManager {
constructor(@IFileService private readonly fileService: IFileService) { }
public async loadFromContentString(contentString: string): Promise<nb.INotebookContents> {
let contents: JSONObject = json.parse(contentString);
@@ -47,11 +50,9 @@ export class LocalContentManager implements nb.ContentManager {
if (!notebookUri) {
return undefined;
}
// TODO validate this is an actual file URI, and error if not
let path = notebookUri.fsPath;
// Note: intentionally letting caller handle exceptions
let notebookFileBuffer = await pfs.readFile(path);
let stringContents = notebookFileBuffer.toString();
let notebookFileBuffer = await this.fileService.readFile(notebookUri);
let stringContents = notebookFileBuffer.value.toString();
let contents: JSONObject = json.parse(stringContents);
if (contents) {
@@ -76,8 +77,7 @@ export class LocalContentManager implements nb.ContentManager {
public async save(notebookUri: URI, notebook: nb.INotebookContents): Promise<nb.INotebookContents> {
// Convert to JSON with pretty-print functionality
let contents = JSON.stringify(notebook, undefined, ' ');
let path = notebookUri.fsPath;
await pfs.writeFile(path, contents);
await this.fileService.writeFile(notebookUri, VSBuffer.fromString(contents));
return notebook;
}

View File

@@ -8,12 +8,12 @@ import * as azdata from 'azdata';
import { Event } from 'vs/base/common/event';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { URI } from 'vs/base/common/uri';
import { RenderMimeRegistry } from 'sql/workbench/parts/notebook/electron-browser/outputs/registry';
import { ModelFactory } from 'sql/workbench/parts/notebook/node/models/modelFactory';
import { RenderMimeRegistry } from 'sql/workbench/parts/notebook/browser/outputs/registry';
import { ModelFactory } from 'sql/workbench/parts/notebook/common/models/modelFactory';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { NotebookInput } from 'sql/workbench/parts/notebook/node/notebookInput';
import { NotebookInput } from 'sql/workbench/parts/notebook/common/models/notebookInput';
import { ISingleNotebookEditOperation } from 'sql/workbench/api/common/sqlExtHostTypes';
import { ICellModel, INotebookModel } from 'sql/workbench/parts/notebook/node/models/modelInterfaces';
import { ICellModel, INotebookModel } from 'sql/workbench/parts/notebook/common/models/modelInterfaces';
import { NotebookChangeType } from 'sql/workbench/parts/notebook/common/models/contracts';
import { IBootstrapParams } from 'sql/platform/bootstrap/common/bootstrapParams';

View File

@@ -12,8 +12,8 @@ import {
INotebookService, INotebookManager, INotebookProvider,
DEFAULT_NOTEBOOK_FILETYPE, INotebookEditor, SQL_NOTEBOOK_PROVIDER, OVERRIDE_EDITOR_THEMING_SETTING, INavigationProvider, ILanguageMagic
} from 'sql/workbench/services/notebook/common/notebookService';
import { RenderMimeRegistry } from 'sql/workbench/parts/notebook/electron-browser/outputs/registry';
import { standardRendererFactories } from 'sql/workbench/parts/notebook/electron-browser/outputs/factories';
import { RenderMimeRegistry } from 'sql/workbench/parts/notebook/browser/outputs/registry';
import { standardRendererFactories } from 'sql/workbench/parts/notebook/browser/outputs/factories';
import { Extensions, INotebookProviderRegistry, NotebookProviderRegistration } from 'sql/workbench/services/notebook/common/notebookRegistry';
import { Emitter, Event } from 'vs/base/common/event';
import { Memento } from 'vs/workbench/common/memento';
@@ -26,11 +26,11 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { NotebookEditorVisibleContext } from 'sql/workbench/services/notebook/common/notebookContext';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { NotebookEditor } from 'sql/workbench/parts/notebook/electron-browser/notebookEditor';
import { NotebookEditor } from 'sql/workbench/parts/notebook/browser/notebookEditor';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { registerNotebookThemes } from 'sql/workbench/parts/notebook/browser/notebookStyles';
import { IQueryManagementService } from 'sql/platform/query/common/queryManagement';
import { notebookConstants } from 'sql/workbench/parts/notebook/node/models/modelInterfaces';
import { notebookConstants } from 'sql/workbench/parts/notebook/common/models/modelInterfaces';
import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle';
import { SqlNotebookProvider } from 'sql/workbench/services/notebook/sql/sqlNotebookProvider';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';

View File

@@ -5,7 +5,7 @@
import { nb } from 'azdata';
import { localize } from 'vs/nls';
import { FutureInternal } from 'sql/workbench/parts/notebook/node/models/modelInterfaces';
import { FutureInternal } from 'sql/workbench/parts/notebook/common/models/modelInterfaces';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
export const noKernel: string = localize('noKernel', "No Kernel");

View File

@@ -8,16 +8,16 @@ import * as vscode from 'vscode';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { SQL_NOTEBOOK_PROVIDER } from 'sql/workbench/services/notebook/common/notebookService';
import { LocalContentManager } from 'sql/workbench/services/notebook/node/localContentManager';
import { LocalContentManager } from 'sql/workbench/services/notebook/common/localContentManager';
import { SqlSessionManager } from 'sql/workbench/services/notebook/sql/sqlSessionManager';
export class SqlNotebookManager implements nb.NotebookProvider {
private _contentManager: nb.ContentManager;
private _sessionManager: nb.SessionManager;
constructor(private _instantiationService: IInstantiationService) {
this._contentManager = new LocalContentManager();
this._sessionManager = new SqlSessionManager(this._instantiationService);
constructor(instantiationService: IInstantiationService) {
this._contentManager = instantiationService.createInstance(LocalContentManager);
this._sessionManager = new SqlSessionManager(instantiationService);
}
public get providerId(): string {

View File

@@ -6,7 +6,7 @@
import * as os from 'os';
import { nb, QueryExecuteSubsetResult, IDbColumn, BatchSummary, IResultMessage, ResultSetSummary } from 'azdata';
import { localize } from 'vs/nls';
import { FutureInternal, notebookConstants } from 'sql/workbench/parts/notebook/node/models/modelInterfaces';
import { FutureInternal, notebookConstants } from 'sql/workbench/parts/notebook/common/models/modelInterfaces';
import QueryRunner from 'sql/platform/query/common/queryRunner';
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
@@ -17,7 +17,7 @@ import { IErrorMessageService } from 'sql/platform/errorMessage/common/errorMess
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { escape } from 'sql/base/common/strings';
import * as notebookUtils from 'sql/workbench/parts/notebook/node/models/notebookUtils';
import * as notebookUtils from 'sql/workbench/parts/notebook/common/models/notebookUtils';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
import { ILogService } from 'vs/platform/log/common/log';