forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from vscode-python-datascience/dev/ianhu/DataSc…
…ienceChanges merge in changes from the old data science branch
- Loading branch information
Showing
12 changed files
with
195 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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>(IApplicationShell); | ||
this.commandManager = this.serviceContainer.get<ICommandManager>(ICommandManager); | ||
this.disposableRegistry = this.serviceContainer.get<IDisposableRegistry>(IDisposableRegistry); | ||
} | ||
|
||
public async activate(): Promise<void> { | ||
this.registerCommands(); | ||
} | ||
|
||
public async executeDataScience(): Promise<void> { | ||
await this.appShell.showInformationMessage('Hello Data Science'); | ||
} | ||
|
||
private registerCommands(): void { | ||
const disposable = this.commandManager.registerCommand(Commands.DataScience, this.executeDataScience, this); | ||
this.disposableRegistry.push(disposable); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<void>; | ||
executeDataScience(): 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IServiceContainer>; | ||
let shell: TypeMoq.IMock<IApplicationShell>; | ||
let commandManager: TypeMoq.IMock<ICommandManager>; | ||
let disposableRegistry: TypeMoq.IMock<IDisposableRegistry>; | ||
let dataScience: IDataScience; | ||
setup(() => { | ||
serviceContainer = TypeMoq.Mock.ofType<IServiceContainer>(); | ||
commandManager = TypeMoq.Mock.ofType<ICommandManager>(); | ||
disposableRegistry = TypeMoq.Mock.ofType<IDisposableRegistry>(); | ||
shell = TypeMoq.Mock.ofType<IApplicationShell>(); | ||
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(); | ||
}); | ||
}); |