Skip to content

Commit

Permalink
Adding interfaces for datascience work (#1) (#2688)
Browse files Browse the repository at this point in the history
* working without inversify

* Working command with service manager

* Initial interfaces
  • Loading branch information
rchiodo authored Sep 25, 2018
1 parent 4a18c8b commit cda22d1
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 8 deletions.
28 changes: 21 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
"onCommand:python.setLinter",
"onCommand:python.enableLinting",
"onCommand:python.createTerminal",
"onCommand:python.discoverTests"
"onCommand:python.discoverTests",
"onCommand:python.datascience"
],
"main": "./out/client/extension",
"contributes": {
Expand Down Expand Up @@ -222,6 +223,11 @@
"command": "python.runLinting",
"title": "%python.command.python.runLinting.title%",
"category": "Python"
},
{
"command": "python.datascience",
"title": "Datascience Command",
"category": "Python Datascience"
}
],
"menus": {
Expand Down
4 changes: 4 additions & 0 deletions src/client/datascience/codewatcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';
31 changes: 31 additions & 0 deletions src/client/datascience/datascience.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

import { inject, injectable } from 'inversify';
import { Disposable, ExtensionContext } from 'vscode';
import { IApplicationShell, ICommandManager } from '../common/application/types';
import { IDisposableRegistry } from '../common/types';
import { IDataScience } from './types';

@injectable()
export class DataScience implements IDataScience {
constructor(@inject(ICommandManager) private commandManager: ICommandManager,
@inject(IDisposableRegistry) private disposableRegistry: Disposable[],
@inject(IApplicationShell) private appShell: IApplicationShell) {
}

public async activate(context: ExtensionContext): Promise<void> {
this.registerCommands();
}

private registerCommands(): void {
const disposable = this.commandManager.registerCommand('python.datascience', this.executeDataScience, this);
this.disposableRegistry.push(disposable);
}

private async executeDataScience(): Promise<void> {
await this.appShell.showInformationMessage('Hello Data Science');
}
}
4 changes: 4 additions & 0 deletions src/client/datascience/history.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';
4 changes: 4 additions & 0 deletions src/client/datascience/historypostoffice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';
16 changes: 16 additions & 0 deletions src/client/datascience/jupyterserverprovider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

import { injectable } from 'inversify';
import { IJupyterServer, IJupyterServerProvider } from './types';

@injectable()
export class JupyterServerProvider implements IJupyterServerProvider {
public start(notebookFile: string | undefined): Promise<IJupyterServer> {
return new Promise<IJupyterServer>((resolve, reject) => {
resolve(undefined);
});
}
}
14 changes: 14 additions & 0 deletions src/client/datascience/serviceRegistry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

import { IServiceManager } from '../ioc/types';
import { DataScience } from './datascience';
import { JupyterServerProvider } from './jupyterserverprovider';
import { IDataScience, IJupyterServerProvider } from './types';

export function registerTypes(serviceManager: IServiceManager) {
serviceManager.addSingleton<IDataScience>(IDataScience, DataScience);
serviceManager.addSingleton<IJupyterServerProvider>(IJupyterServerProvider, JupyterServerProvider);
}
50 changes: 50 additions & 0 deletions src/client/datascience/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

'use strict';

import { ExtensionContext } from 'vscode';

// Main interface
export const IDataScience = Symbol('IDataScience');
export interface IDataScience {
activate(context: ExtensionContext): Promise<void>;
}

// Factory for jupyter servers
export const IJupyterServerProvider = Symbol('IJupyterServerFactory');
export interface IJupyterServerProvider {
start(notebookFile: string | undefined): Promise<IJupyterServer>;
}

// Talks to a jupyter kernel to retrieve data for cells
export const IJupyterServer = Symbol('IJupyterServer');
export interface IJupyterServer {
}

// Wraps the VS Code api for creating a web panel
export const IWebPanelProvider = Symbol('IWebPanelProvider');
export interface IWebPanelProvider {
create(): IWebPanel;
}

// Wraps the VS Code webview panel
export const IWebPanel = Symbol('IWebPanel');
export interface IWebPanel {
}

// Wraps the vscode API in order to send messages back and forth from a webview
export const IPostOffice = Symbol('IPostOffice');
export interface IPostOffice {
// tslint:disable-next-line:no-any
post(message: string, params: any[] | undefined);
// tslint:disable-next-line:no-any
listen(message: string, listener: (args: any[] | undefined) => void);
}

// Basic structure for a cell from a notebook
export interface ICell {
input: string;
output: string;
id: number;
}
7 changes: 7 additions & 0 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import {
IMemento, IOutputChannel, WORKSPACE_MEMENTO
} from './common/types';
import { registerTypes as variableRegisterTypes } from './common/variables/serviceRegistry';
import { registerTypes as dataScienceRegisterTypes } from './datascience/serviceRegistry';
import { IDataScience } from './datascience/types';
import { AttachRequestArguments, LaunchRequestArguments } from './debugger/Common/Contracts';
import { BaseConfigurationProvider } from './debugger/configProviders/baseProvider';
import { registerTypes as debugConfigurationRegisterTypes } from './debugger/configProviders/serviceRegistry';
Expand Down Expand Up @@ -105,6 +107,10 @@ export async function activate(context: ExtensionContext): Promise<IExtensionApi
const lintingEngine = serviceManager.get<ILintingEngine>(ILintingEngine);
lintingEngine.linkJupiterExtension(jupyterExtension).ignoreErrors();

// Activate the data science features
const dataScience = serviceManager.get<IDataScience>(IDataScience);
await dataScience.activate(context);

context.subscriptions.push(new LinterCommands(serviceManager));
const linterProvider = new LinterProvider(context, serviceManager);
context.subscriptions.push(linterProvider);
Expand Down Expand Up @@ -185,6 +191,7 @@ function registerServices(context: ExtensionContext, serviceManager: ServiceMana
platformRegisterTypes(serviceManager);
installerRegisterTypes(serviceManager);
commonRegisterTerminalTypes(serviceManager);
dataScienceRegisterTypes(serviceManager);
debugConfigurationRegisterTypes(serviceManager);
debuggerRegisterTypes(serviceManager);
appRegisterTypes(serviceManager);
Expand Down

0 comments on commit cda22d1

Please sign in to comment.