Skip to content

Commit cda22d1

Browse files
authored
Adding interfaces for datascience work (#1) (#2688)
* working without inversify * Working command with service manager * Initial interfaces
1 parent 4a18c8b commit cda22d1

10 files changed

+158
-8
lines changed

package-lock.json

+21-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@
8585
"onCommand:python.setLinter",
8686
"onCommand:python.enableLinting",
8787
"onCommand:python.createTerminal",
88-
"onCommand:python.discoverTests"
88+
"onCommand:python.discoverTests",
89+
"onCommand:python.datascience"
8990
],
9091
"main": "./out/client/extension",
9192
"contributes": {
@@ -222,6 +223,11 @@
222223
"command": "python.runLinting",
223224
"title": "%python.command.python.runLinting.title%",
224225
"category": "Python"
226+
},
227+
{
228+
"command": "python.datascience",
229+
"title": "Datascience Command",
230+
"category": "Python Datascience"
225231
}
226232
],
227233
"menus": {

src/client/datascience/codewatcher.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';

src/client/datascience/datascience.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
import { inject, injectable } from 'inversify';
7+
import { Disposable, ExtensionContext } from 'vscode';
8+
import { IApplicationShell, ICommandManager } from '../common/application/types';
9+
import { IDisposableRegistry } from '../common/types';
10+
import { IDataScience } from './types';
11+
12+
@injectable()
13+
export class DataScience implements IDataScience {
14+
constructor(@inject(ICommandManager) private commandManager: ICommandManager,
15+
@inject(IDisposableRegistry) private disposableRegistry: Disposable[],
16+
@inject(IApplicationShell) private appShell: IApplicationShell) {
17+
}
18+
19+
public async activate(context: ExtensionContext): Promise<void> {
20+
this.registerCommands();
21+
}
22+
23+
private registerCommands(): void {
24+
const disposable = this.commandManager.registerCommand('python.datascience', this.executeDataScience, this);
25+
this.disposableRegistry.push(disposable);
26+
}
27+
28+
private async executeDataScience(): Promise<void> {
29+
await this.appShell.showInformationMessage('Hello Data Science');
30+
}
31+
}

src/client/datascience/history.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
import { injectable } from 'inversify';
7+
import { IJupyterServer, IJupyterServerProvider } from './types';
8+
9+
@injectable()
10+
export class JupyterServerProvider implements IJupyterServerProvider {
11+
public start(notebookFile: string | undefined): Promise<IJupyterServer> {
12+
return new Promise<IJupyterServer>((resolve, reject) => {
13+
resolve(undefined);
14+
});
15+
}
16+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
import { IServiceManager } from '../ioc/types';
7+
import { DataScience } from './datascience';
8+
import { JupyterServerProvider } from './jupyterserverprovider';
9+
import { IDataScience, IJupyterServerProvider } from './types';
10+
11+
export function registerTypes(serviceManager: IServiceManager) {
12+
serviceManager.addSingleton<IDataScience>(IDataScience, DataScience);
13+
serviceManager.addSingleton<IJupyterServerProvider>(IJupyterServerProvider, JupyterServerProvider);
14+
}

src/client/datascience/types.ts

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
import { ExtensionContext } from 'vscode';
7+
8+
// Main interface
9+
export const IDataScience = Symbol('IDataScience');
10+
export interface IDataScience {
11+
activate(context: ExtensionContext): Promise<void>;
12+
}
13+
14+
// Factory for jupyter servers
15+
export const IJupyterServerProvider = Symbol('IJupyterServerFactory');
16+
export interface IJupyterServerProvider {
17+
start(notebookFile: string | undefined): Promise<IJupyterServer>;
18+
}
19+
20+
// Talks to a jupyter kernel to retrieve data for cells
21+
export const IJupyterServer = Symbol('IJupyterServer');
22+
export interface IJupyterServer {
23+
}
24+
25+
// Wraps the VS Code api for creating a web panel
26+
export const IWebPanelProvider = Symbol('IWebPanelProvider');
27+
export interface IWebPanelProvider {
28+
create(): IWebPanel;
29+
}
30+
31+
// Wraps the VS Code webview panel
32+
export const IWebPanel = Symbol('IWebPanel');
33+
export interface IWebPanel {
34+
}
35+
36+
// Wraps the vscode API in order to send messages back and forth from a webview
37+
export const IPostOffice = Symbol('IPostOffice');
38+
export interface IPostOffice {
39+
// tslint:disable-next-line:no-any
40+
post(message: string, params: any[] | undefined);
41+
// tslint:disable-next-line:no-any
42+
listen(message: string, listener: (args: any[] | undefined) => void);
43+
}
44+
45+
// Basic structure for a cell from a notebook
46+
export interface ICell {
47+
input: string;
48+
output: string;
49+
id: number;
50+
}

src/client/extension.ts

+7
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import {
3030
IMemento, IOutputChannel, WORKSPACE_MEMENTO
3131
} from './common/types';
3232
import { registerTypes as variableRegisterTypes } from './common/variables/serviceRegistry';
33+
import { registerTypes as dataScienceRegisterTypes } from './datascience/serviceRegistry';
34+
import { IDataScience } from './datascience/types';
3335
import { AttachRequestArguments, LaunchRequestArguments } from './debugger/Common/Contracts';
3436
import { BaseConfigurationProvider } from './debugger/configProviders/baseProvider';
3537
import { registerTypes as debugConfigurationRegisterTypes } from './debugger/configProviders/serviceRegistry';
@@ -105,6 +107,10 @@ export async function activate(context: ExtensionContext): Promise<IExtensionApi
105107
const lintingEngine = serviceManager.get<ILintingEngine>(ILintingEngine);
106108
lintingEngine.linkJupiterExtension(jupyterExtension).ignoreErrors();
107109

110+
// Activate the data science features
111+
const dataScience = serviceManager.get<IDataScience>(IDataScience);
112+
await dataScience.activate(context);
113+
108114
context.subscriptions.push(new LinterCommands(serviceManager));
109115
const linterProvider = new LinterProvider(context, serviceManager);
110116
context.subscriptions.push(linterProvider);
@@ -185,6 +191,7 @@ function registerServices(context: ExtensionContext, serviceManager: ServiceMana
185191
platformRegisterTypes(serviceManager);
186192
installerRegisterTypes(serviceManager);
187193
commonRegisterTerminalTypes(serviceManager);
194+
dataScienceRegisterTypes(serviceManager);
188195
debugConfigurationRegisterTypes(serviceManager);
189196
debuggerRegisterTypes(serviceManager);
190197
appRegisterTypes(serviceManager);

0 commit comments

Comments
 (0)