diff --git a/package.json b/package.json index b0656158cd4f..2c0d095066f6 100644 --- a/package.json +++ b/package.json @@ -222,6 +222,11 @@ "command": "python.runLinting", "title": "%python.command.python.runLinting.title%", "category": "Python" + }, + { + "command": "python.datascience", + "title": "%python.command.python.datascience.datascience.title%", + "category": "Python" } ], "menus": { diff --git a/package.nls.json b/package.nls.json index 333a94791381..b8ab9f88c200 100644 --- a/package.nls.json +++ b/package.nls.json @@ -23,6 +23,7 @@ "python.command.python.setLinter.title": "Select Linter", "python.command.python.enableLinting.title": "Enable Linting", "python.command.python.runLinting.title": "Run Linting", + "python.command.python.datascience.datascience.title": "Data Science Test Command", "python.snippet.launch.standard.label": "Python: Current File", "python.snippet.launch.standard.description": "Debug a Python Program with Standard Output", "python.snippet.launch.pyspark.label": "Python: PySpark", diff --git a/src/client/datascience/codewatcher.ts b/src/client/datascience/codewatcher.ts new file mode 100644 index 000000000000..85bf63caa5bb --- /dev/null +++ b/src/client/datascience/codewatcher.ts @@ -0,0 +1,4 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +'use strict'; diff --git a/src/client/datascience/constants.ts b/src/client/datascience/constants.ts new file mode 100644 index 000000000000..5d8e391b2f94 --- /dev/null +++ b/src/client/datascience/constants.ts @@ -0,0 +1,8 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +'use strict'; + +export namespace Commands { + export const DataScience = 'python.datascience'; +} diff --git a/src/client/datascience/datascience.ts b/src/client/datascience/datascience.ts new file mode 100644 index 000000000000..be735aa1d660 --- /dev/null +++ b/src/client/datascience/datascience.ts @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +'use strict'; + +import { inject, injectable } from 'inversify'; +import { IApplicationShell, ICommandManager } from '../common/application/types'; +import { IDisposableRegistry } from '../common/types'; +import { IServiceContainer } from '../ioc/types'; +import { Commands } from './constants'; +import { IDataScience } from './types'; + +@injectable() +export class DataScience implements IDataScience { + private readonly appShell: IApplicationShell; + private readonly commandManager: ICommandManager; + private readonly disposableRegistry: IDisposableRegistry; + constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer) + { + this.appShell = this.serviceContainer.get(IApplicationShell); + this.commandManager = this.serviceContainer.get(ICommandManager); + this.disposableRegistry = this.serviceContainer.get(IDisposableRegistry); + } + + public async activate(): Promise { + this.registerCommands(); + } + + public async executeDataScience(): Promise { + await this.appShell.showInformationMessage('Hello Data Science'); + } + + private registerCommands(): void { + const disposable = this.commandManager.registerCommand(Commands.DataScience, this.executeDataScience, this); + this.disposableRegistry.push(disposable); + } +} diff --git a/src/client/datascience/history.ts b/src/client/datascience/history.ts new file mode 100644 index 000000000000..85bf63caa5bb --- /dev/null +++ b/src/client/datascience/history.ts @@ -0,0 +1,4 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +'use strict'; diff --git a/src/client/datascience/historypostoffice.ts b/src/client/datascience/historypostoffice.ts new file mode 100644 index 000000000000..85bf63caa5bb --- /dev/null +++ b/src/client/datascience/historypostoffice.ts @@ -0,0 +1,4 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +'use strict'; diff --git a/src/client/datascience/jupyterserverprovider.ts b/src/client/datascience/jupyterserverprovider.ts new file mode 100644 index 000000000000..aff6473430f9 --- /dev/null +++ b/src/client/datascience/jupyterserverprovider.ts @@ -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 { + return new Promise((resolve, reject) => { + resolve(undefined); + }); + } +} diff --git a/src/client/datascience/serviceRegistry.ts b/src/client/datascience/serviceRegistry.ts new file mode 100644 index 000000000000..0c1d2e6bdeea --- /dev/null +++ b/src/client/datascience/serviceRegistry.ts @@ -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, DataScience); + serviceManager.addSingleton(IJupyterServerProvider, JupyterServerProvider); +} diff --git a/src/client/datascience/types.ts b/src/client/datascience/types.ts new file mode 100644 index 000000000000..4ca8e1a6d1f1 --- /dev/null +++ b/src/client/datascience/types.ts @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +'use strict'; + +// Main interface +export const IDataScience = Symbol('IDataScience'); +export interface IDataScience { + activate(): Promise; + executeDataScience(): Promise; +} + +// Factory for jupyter servers +export const IJupyterServerProvider = Symbol('IJupyterServerFactory'); +export interface IJupyterServerProvider { + start(notebookFile: string | undefined): Promise; +} + +// 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; +} diff --git a/src/client/extension.ts b/src/client/extension.ts index 66986f0996c1..5baa57fadc02 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -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'; @@ -105,6 +107,10 @@ export async function activate(context: ExtensionContext): Promise(ILintingEngine); lintingEngine.linkJupiterExtension(jupyterExtension).ignoreErrors(); + // Activate data science features + const dataScience = serviceManager.get(IDataScience); + dataScience.activate().ignoreErrors(); + context.subscriptions.push(new LinterCommands(serviceManager)); const linterProvider = new LinterProvider(context, serviceManager); context.subscriptions.push(linterProvider); @@ -185,6 +191,7 @@ function registerServices(context: ExtensionContext, serviceManager: ServiceMana platformRegisterTypes(serviceManager); installerRegisterTypes(serviceManager); commonRegisterTerminalTypes(serviceManager); + dataScienceRegisterTypes(serviceManager); debugConfigurationRegisterTypes(serviceManager); debuggerRegisterTypes(serviceManager); appRegisterTypes(serviceManager); diff --git a/src/test/datascience/datascience.unit.test.ts b/src/test/datascience/datascience.unit.test.ts new file mode 100644 index 000000000000..cb9fd6395336 --- /dev/null +++ b/src/test/datascience/datascience.unit.test.ts @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +'use strict'; + +import * as TypeMoq from 'typemoq'; +import { IApplicationShell, ICommandManager } from '../../client/common/application/types'; +import { IDisposableRegistry } from '../../client/common/types'; +import { Commands } from '../../client/datascience/constants'; +import { DataScience } from '../../client/datascience/datascience'; +import { IDataScience } from '../../client/datascience/types'; +import { IServiceContainer } from '../../client/ioc/types'; + +suite('Data Science Tests', () => { + let serviceContainer: TypeMoq.IMock; + let shell: TypeMoq.IMock; + let commandManager: TypeMoq.IMock; + let disposableRegistry: TypeMoq.IMock; + let dataScience: IDataScience; + setup(() => { + serviceContainer = TypeMoq.Mock.ofType(); + commandManager = TypeMoq.Mock.ofType(); + disposableRegistry = TypeMoq.Mock.ofType(); + shell = TypeMoq.Mock.ofType(); + serviceContainer.setup(c => c.get(ICommandManager)).returns(() => commandManager.object); + serviceContainer.setup(c => c.get(IApplicationShell)).returns(() => shell.object); + serviceContainer.setup(c => c.get(IDisposableRegistry)).returns(() => disposableRegistry.object); + + dataScience = new DataScience(serviceContainer.object); + }); + test('Ensure command is registered on activation', async () => { + commandManager + .setup(c => c.registerCommand(TypeMoq.It.isValue(Commands.DataScience), TypeMoq.It.isAny(), TypeMoq.It.isValue(dataScience))) + .verifiable(TypeMoq.Times.once()); + await dataScience.activate(); + commandManager.verifyAll(); + }); + test('Check message from datascience command', async () => { + shell + .setup(s => s.showInformationMessage(TypeMoq.It.isValue('Hello Data Science'))) + .returns(() => Promise.resolve(undefined)) + .verifiable(TypeMoq.Times.once()); + await dataScience.executeDataScience(); + shell.verifyAll(); + }); +});