Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kernel selection UI #8866

Merged
merged 22 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.
'use strict';
import * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api';

import { IKernel } from '../../../datascience-ui/interactive-common/mainState';
import { CssMessages, IGetCssRequest, IGetCssResponse, IGetMonacoThemeRequest } from '../messages';
import { IGetMonacoThemeResponse } from '../monacoMessages';
import { ICell, IInteractiveWindowInfo, IJupyterVariable, IJupyterVariablesResponse } from '../types';
Expand Down Expand Up @@ -83,7 +83,9 @@ export enum InteractiveWindowMessages {
ExecutionRendered = 'rendered_execution',
FocusedCellEditor = 'focused_cell_editor',
MonacoReady = 'monaco_ready',
ClearAllOutputs = 'clear_all_outputs'
ClearAllOutputs = 'clear_all_outputs',
SelectKernel = 'select_kernel',
UpdateKernel = 'update_kernel'
}

export enum NativeCommandType {
Expand All @@ -107,6 +109,7 @@ export enum NativeCommandType {
RunAndAdd,
RunAndMove,
RunBelow,
SelectKernel,
ToggleLineNumbers,
ToggleOutput,
ToggleVariableExplorer,
Expand Down Expand Up @@ -283,6 +286,7 @@ export class IInteractiveWindowMapping {
public [InteractiveWindowMessages.CopyCodeCell]: ICopyCode;
public [InteractiveWindowMessages.NotebookExecutionActivated]: string;
public [InteractiveWindowMessages.RestartKernel]: never | undefined;
public [InteractiveWindowMessages.SelectKernel]: IKernel | undefined;
public [InteractiveWindowMessages.Export]: ICell[];
public [InteractiveWindowMessages.GetAllCells]: ICell;
public [InteractiveWindowMessages.ReturnAllCells]: ICell[];
Expand Down Expand Up @@ -354,4 +358,5 @@ export class IInteractiveWindowMapping {
public [InteractiveWindowMessages.FocusedCellEditor]: IFocusedCellEditor;
public [InteractiveWindowMessages.MonacoReady]: never | undefined;
public [InteractiveWindowMessages.ClearAllOutputs]: never | undefined;
public [InteractiveWindowMessages.UpdateKernel]: IKernel | undefined;
}
15 changes: 14 additions & 1 deletion src/client/datascience/interactive-ipynb/nativeEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import { IInterpreterService } from '../../interpreter/contracts';
import { captureTelemetry, sendTelemetryEvent } from '../../telemetry';
import { concatMultilineStringInput, splitMultilineString } from '../common';
import { EditorContexts, Identifiers, NativeKeyboardCommandTelemetryLookup, NativeMouseCommandTelemetryLookup, Telemetry } from '../constants';
import { DataScience } from '../datascience';
import { InteractiveBase } from '../interactive-common/interactiveBase';
import { IEditCell, IInsertCell, INativeCommand, InteractiveWindowMessages, IRemoveCell, ISaveAll, ISubmitNewCell, ISwapCells } from '../interactive-common/interactiveWindowTypes';
import { InvalidNotebookFileError } from '../jupyter/invalidNotebookFileError';
import { CellState, ICell, ICodeCssGenerator, IDataScienceErrorHandler, IDataViewerProvider, IInteractiveWindowInfo, IInteractiveWindowListener, IJupyterDebugger, IJupyterExecution, IJupyterVariables, INotebookEditor, INotebookEditorProvider, INotebookExporter, INotebookImporter, INotebookServerOptions, IStatusProvider, IThemeFinder } from '../types';
import { CellState, ICell, ICodeCssGenerator, IDataScience, IDataScienceErrorHandler, IDataViewerProvider, IInteractiveWindowInfo, IInteractiveWindowListener, IJupyterDebugger, IJupyterExecution, IJupyterVariables, INotebookEditor, INotebookEditorProvider, INotebookExporter, INotebookImporter, INotebookServerOptions, IStatusProvider, IThemeFinder } from '../types';

const nativeEditorDir = path.join(EXTENSION_ROOT_DIR, 'out', 'datascience-ui', 'native-editor');
enum AskForSaveResult {
Expand Down Expand Up @@ -72,6 +73,7 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {
@inject(IJupyterDebugger) jupyterDebugger: IJupyterDebugger,
@inject(INotebookImporter) private importer: INotebookImporter,
@inject(IDataScienceErrorHandler) errorHandler: IDataScienceErrorHandler,
@inject(IDataScience) private dataScience: DataScience,
@inject(IMemento) @named(GLOBAL_MEMENTO) private globalStorage: Memento,
@inject(IMemento) @named(WORKSPACE_MEMENTO) private localStorage: Memento
) {
Expand Down Expand Up @@ -225,6 +227,10 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {
this.handleMessage(message, payload, this.clearAllOutputs);
break;

case InteractiveWindowMessages.SelectKernel:
this.handleMessage(message, payload, this.selectKernel);
break;

default:
break;
}
Expand Down Expand Up @@ -897,4 +903,11 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {

await this.setDirty();
}

private async selectKernel() {
await this.dataScience.selectJupyterURI();

const settings = this.configuration.getSettings();
await this.postMessage(InteractiveWindowMessages.UpdateKernel, { status: 'Idle', state: settings.datascience.jupyterServerURI, version: '3' });
DavidKutu marked this conversation as resolved.
Show resolved Hide resolved
DavidKutu marked this conversation as resolved.
Show resolved Hide resolved
}
}
20 changes: 5 additions & 15 deletions src/datascience-ui/history-react/redux/mapping.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import {
IRefreshVariablesRequest,
IScrollToCell
} from '../../../client/datascience/interactive-common/interactiveWindowTypes';
import { IRefreshVariablesRequest, IScrollToCell } from '../../../client/datascience/interactive-common/interactiveWindowTypes';
import { IGetCssResponse } from '../../../client/datascience/messages';
import { IGetMonacoThemeResponse } from '../../../client/datascience/monacoMessages';
import { ICell, IJupyterVariable, IJupyterVariablesResponse } from '../../../client/datascience/types';
import { IMainState } from '../../interactive-common/mainState';
import { IKernel, IMainState } from '../../interactive-common/mainState';
DavidKutu marked this conversation as resolved.
Show resolved Hide resolved
import { IncomingMessageActions } from '../../interactive-common/redux/postOffice';
import {
CommonActionType,
ICellAction,
ICodeAction,
IEditCellAction,
ILinkClickAction,
IScrollAction,
IShowDataViewerAction,
IShowPlotAction
} from '../../interactive-common/redux/reducers/types';
import { CommonActionType, ICellAction, ICodeAction, IEditCellAction, ILinkClickAction, IScrollAction, IShowDataViewerAction, IShowPlotAction } from '../../interactive-common/redux/reducers/types';
DavidKutu marked this conversation as resolved.
Show resolved Hide resolved
import { ReducerArg, ReducerFunc } from '../../react-common/reduxUtils';

type InteractiveReducerFunc<T> = ReducerFunc<IMainState, CommonActionType, T>;
Expand All @@ -30,6 +18,7 @@ export class IInteractiveActionMapping {
public [CommonActionType.TOGGLE_VARIABLE_EXPLORER]: InteractiveReducerFunc<never | undefined>;
public [CommonActionType.REFRESH_VARIABLES]: InteractiveReducerFunc<IRefreshVariablesRequest>;
public [CommonActionType.RESTART_KERNEL]: InteractiveReducerFunc<never | undefined>;
public [CommonActionType.SELECT_KERNEL]: InteractiveReducerFunc<never | undefined>;
public [CommonActionType.INTERRUPT_KERNEL]: InteractiveReducerFunc<never | undefined>;
public [CommonActionType.EXPORT]: InteractiveReducerFunc<never | undefined>;
public [CommonActionType.SAVE]: InteractiveReducerFunc<never | undefined>;
Expand Down Expand Up @@ -75,4 +64,5 @@ export class IInteractiveActionMapping {
public [IncomingMessageActions.STARTDEBUGGING]: InteractiveReducerFunc<never | undefined>;
public [IncomingMessageActions.STOPDEBUGGING]: InteractiveReducerFunc<never | undefined>;
public [IncomingMessageActions.SCROLLTOCELL]: InteractiveReducerFunc<IScrollToCell>;
public [IncomingMessageActions.UPDATEKERNEL]: InteractiveReducerFunc<IKernel>;
}
4 changes: 3 additions & 1 deletion src/datascience-ui/history-react/redux/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const reducerMap: IInteractiveActionMapping = {
[CommonActionType.REFRESH_VARIABLES]: Variables.refreshVariables,
[CommonActionType.RESTART_KERNEL]: Kernel.restartKernel,
[CommonActionType.INTERRUPT_KERNEL]: Kernel.interruptKernel,
[CommonActionType.SELECT_KERNEL]: Kernel.selectJupyterURI,
[CommonActionType.EXPORT]: Transfer.exportCells,
[CommonActionType.SAVE]: Transfer.save,
[CommonActionType.SHOW_DATA_VIEWER]: Transfer.showDataViewer,
Expand Down Expand Up @@ -62,5 +63,6 @@ export const reducerMap: IInteractiveActionMapping = {
[IncomingMessageActions.UPDATESETTINGS]: Effects.updateSettings,
[IncomingMessageActions.STARTDEBUGGING]: Execution.startDebugging,
[IncomingMessageActions.STOPDEBUGGING]: Execution.stopDebugging,
[IncomingMessageActions.SCROLLTOCELL]: Effects.scrollToCell
[IncomingMessageActions.SCROLLTOCELL]: Effects.scrollToCell,
[IncomingMessageActions.UPDATEKERNEL]: Kernel.updateStatus
};
14 changes: 13 additions & 1 deletion src/datascience-ui/interactive-common/mainState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,20 @@ export type IMainState = {
activateCount: number;
monacoReady: boolean;
loaded: boolean;
kernel: IKernel;
};

export interface IFont {
size: number;
family: string;
}

export interface IKernel {
status: string;
DavidKutu marked this conversation as resolved.
Show resolved Hide resolved
state: string;
version: string;
DavidKutu marked this conversation as resolved.
Show resolved Hide resolved
}

// tslint:disable-next-line: no-multiline-string
const darkStyle = `
:root {
Expand Down Expand Up @@ -135,7 +142,12 @@ export function generateTestState(filePath: string = '', editable: boolean = fal
activateCount: 0,
monacoReady: true,
loaded: false,
testMode: true
testMode: true,
kernel: {
state: 'No Kernel',
DavidKutu marked this conversation as resolved.
Show resolved Hide resolved
version: '3',
status: 'Not started'
DavidKutu marked this conversation as resolved.
Show resolved Hide resolved
}
};
}

Expand Down
3 changes: 2 additions & 1 deletion src/datascience-ui/interactive-common/redux/postOffice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ export enum IncomingMessageActions {
GETCSSREQUEST = 'action.get_css_request',
GETCSSRESPONSE = 'action.get_css_response',
GETMONACOTHEMEREQUEST = 'action.get_monaco_theme_request',
GETMONACOTHEMERESPONSE = 'action.get_monaco_theme_response'
GETMONACOTHEMERESPONSE = 'action.get_monaco_theme_response',
UPDATEKERNEL = 'action.update_kernel'
}

export const AllowedMessages = [...Object.values(InteractiveWindowMessages), ...Object.values(CssMessages)];
Expand Down
18 changes: 17 additions & 1 deletion src/datascience-ui/interactive-common/redux/reducers/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
'use strict';
import { InteractiveWindowMessages } from '../../../../client/datascience/interactive-common/interactiveWindowTypes';
import { CellState } from '../../../../client/datascience/types';
import { IMainState } from '../../mainState';
import { IKernel, IMainState } from '../../mainState';
import { createPostableAction } from '../postOffice';
import { CommonReducerArg } from './types';

export namespace Kernel {
export function selectJupyterURI<T>(arg: CommonReducerArg<T>): IMainState {
arg.queueAction(createPostableAction(InteractiveWindowMessages.SelectKernel));

return arg.prevState;
}
export function restartKernel<T>(arg: CommonReducerArg<T>): IMainState {
arg.queueAction(createPostableAction(InteractiveWindowMessages.RestartKernel));

Expand All @@ -22,6 +27,17 @@ export namespace Kernel {
return arg.prevState;
}

export function updateStatus<T>(arg: CommonReducerArg<T, IKernel>): IMainState {
return {
...arg.prevState,
kernel: {
state: arg.payload.state,
status: arg.payload.status,
version: arg.payload.version
}
};
}

export function handleRestarted<T>(arg: CommonReducerArg<T>) {
// When we restart, make sure to turn off all executing cells. They aren't executing anymore
const newVMs = [...arg.prevState.cellVMs];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export enum CommonActionType {
SAVE = 'action.save',
SCROLL = 'action.scroll',
SELECT_CELL = 'action.select_cell',
SELECT_KERNEL = 'action.select_kernel',
SEND_COMMAND = 'action.send_command',
SHOW_DATA_VIEWER = 'action.show_data_viewer',
SHOW_PLOT = 'action.show_plot',
Expand Down
19 changes: 12 additions & 7 deletions src/datascience-ui/interactive-common/redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ function generateDefaultState(skipDefault: boolean, testMode: boolean, baseTheme
settings: defaultSettings,
activateCount: 0,
monacoReady: testMode, // When testing, monaco starts out ready
loaded: false
loaded: false,
kernel: {
version: '3',
state: 'No Kernel',
status: 'Not started'
}
};
}
}
Expand Down Expand Up @@ -148,14 +153,14 @@ function createMiddleWare(testMode: boolean): Redux.Middleware<{}, IStore>[] {
const logger = createLogger({
// tslint:disable-next-line: no-any
stateTransformer: (state: any) => {
if (!state || typeof state !== 'object'){
if (!state || typeof state !== 'object') {
return state;
}
// tslint:disable-next-line: no-any
const rootState = {...state} as any;
if ('main' in rootState && typeof rootState.main === 'object'){
const rootState = { ...state } as any;
if ('main' in rootState && typeof rootState.main === 'object') {
// tslint:disable-next-line: no-any
const main = rootState.main = {...rootState.main} as any as Partial<IMainState>;
const main = rootState.main = { ...rootState.main } as any as Partial<IMainState>;
main.rootCss = reduceLogMessage;
main.rootStyle = reduceLogMessage;
// tslint:disable-next-line: no-any
Expand All @@ -169,10 +174,10 @@ function createMiddleWare(testMode: boolean): Redux.Middleware<{}, IStore>[] {
},
// tslint:disable-next-line: no-any
actionTransformer: (action: any) => {
if (!action){
if (!action) {
return action;
}
if (actionsWithLargePayload.indexOf(action.type) >= 0){
if (actionsWithLargePayload.indexOf(action.type) >= 0) {
return { ...action, payload: reduceLogMessage };
}
return action;
Expand Down
27 changes: 27 additions & 0 deletions src/datascience-ui/native-editor/nativeEditor.less
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,33 @@
margin-top: 3px;
}

.kernel-status {
position: absolute;
right: 3px;
margin-top: 2px;
color: var(--vscode-editorGutter-commentRangeForeground);
DavidKutu marked this conversation as resolved.
Show resolved Hide resolved
}

.kernel-status-section {
float: left;
padding: 2px 5px 2px 5px;
}

.kernel-status-section:hover {
background-color: var(--override-widget-background, var(--vscode-notifications-background));
}

.kernel-status-divider {
border-left: 1px solid var(--vscode-badge-background);
height: 17px;
margin: 0 5px 0 5px;
float: left;
}

.kernel-status:hover {
cursor: pointer;
}

#toolbar-panel {
margin-top: 2px;
margin-bottom: 2px;
Expand Down
15 changes: 15 additions & 0 deletions src/datascience-ui/native-editor/nativeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ export class NativeEditor extends React.Component<INativeEditorProps> {

// tslint:disable: react-this-binding-issue
private renderToolbarPanel() {
const dynamicFont: React.CSSProperties = {
fontSize: this.props.font.size - 2,
DavidKutu marked this conversation as resolved.
Show resolved Hide resolved
fontFamily: this.props.font.family
};

const selectedIndex = this.props.cellVMs.findIndex(c => c.cell.id === this.props.selectedCellId);

const addCell = () => {
Expand Down Expand Up @@ -145,6 +150,10 @@ export class NativeEditor extends React.Component<INativeEditorProps> {
this.props.sendCommand(NativeCommandType.RunBelow, 'mouse');
}
};
const selectKernel = () => {
this.props.selectKernel();
this.props.sendCommand(NativeCommandType.SelectKernel, 'mouse');
DavidKutu marked this conversation as resolved.
Show resolved Hide resolved
};
const canRunAbove = selectedIndex > 0;
const canRunBelow = selectedIndex < this.props.cellVMs.length - 1 && this.props.selectedCellId;

Expand Down Expand Up @@ -181,6 +190,12 @@ export class NativeEditor extends React.Component<INativeEditorProps> {
<ImageButton baseTheme={this.props.baseTheme} onClick={this.props.export} disabled={!this.props.cellVMs.length} className='native-button' tooltip={getLocString('DataScience.exportAsPythonFileTooltip', 'Save As Python File')}>
<Image baseTheme={this.props.baseTheme} class='image-button-image' image={ImageName.ExportToPython} />
</ImageButton>
<div onClick={selectKernel} className='kernel-status' style={dynamicFont} role='toolbar'>
<div className='kernel-status-section'>Jupyter Server: {this.props.kernel.state}</div>
DavidKutu marked this conversation as resolved.
Show resolved Hide resolved
<div className='kernel-status-divider'/>
<div className='kernel-status-section'>Python {this.props.kernel.version}:</div>
DavidKutu marked this conversation as resolved.
Show resolved Hide resolved
<div className='kernel-status-section'>{this.props.kernel.status}</div>
</div>
</div>
<div className='toolbar-divider'/>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/datascience-ui/native-editor/redux/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ export const actionCreators = {
editorLoaded: (): CommonAction<never | undefined> => ({ type: CommonActionType.EDITOR_LOADED }),
codeCreated: (cellId: string | undefined, modelId: string): CommonAction<ICodeCreatedAction> => ({ type: CommonActionType.CODE_CREATED, payload: { cellId, modelId } }),
loadedAllCells: (): CommonAction<never | undefined> => ({ type: CommonActionType.LOADED_ALL_CELLS }),
editorUnmounted: (): CommonAction<never | undefined> => ({ type: CommonActionType.UNMOUNT })
editorUnmounted: (): CommonAction<never | undefined> => ({ type: CommonActionType.UNMOUNT }),
selectKernel: (): CommonAction<never | undefined> => ({ type: CommonActionType.SELECT_KERNEL })
};
19 changes: 4 additions & 15 deletions src/datascience-ui/native-editor/redux/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,9 @@ import { ILoadAllCells } from '../../../client/datascience/interactive-common/in
import { IGetCssResponse } from '../../../client/datascience/messages';
import { IGetMonacoThemeResponse } from '../../../client/datascience/monacoMessages';
import { ICell, IJupyterVariable, IJupyterVariablesResponse } from '../../../client/datascience/types';
import { IMainState } from '../../interactive-common/mainState';
import { IKernel, IMainState } from '../../interactive-common/mainState';
import { IncomingMessageActions } from '../../interactive-common/redux/postOffice';
import {
CommonActionType,
ICellAction,
ICellAndCursorAction,
IChangeCellTypeAction,
ICodeAction,
IEditCellAction,
IExecuteAction,
ILinkClickAction,
IRefreshVariablesAction,
ISendCommandAction,
IShowDataViewerAction,
IShowPlotAction
} from '../../interactive-common/redux/reducers/types';
import { CommonActionType, ICellAction, ICellAndCursorAction, IChangeCellTypeAction, ICodeAction, IEditCellAction, IExecuteAction, ILinkClickAction, IRefreshVariablesAction, ISendCommandAction, IShowDataViewerAction, IShowPlotAction } from '../../interactive-common/redux/reducers/types';
import { ReducerArg, ReducerFunc } from '../../react-common/reduxUtils';

type NativeEditorReducerFunc<T> = ReducerFunc<IMainState, CommonActionType, T>;
Expand Down Expand Up @@ -65,6 +52,7 @@ export class INativeEditorActionMapping {
public [CommonActionType.EDITOR_LOADED]: NativeEditorReducerFunc<never | undefined>;
public [CommonActionType.LOADED_ALL_CELLS]: NativeEditorReducerFunc<never | undefined>;
public [CommonActionType.UNMOUNT]: NativeEditorReducerFunc<never | undefined>;
public [CommonActionType.SELECT_KERNEL]: NativeEditorReducerFunc<never | undefined>;

// Messages from the extension
public [IncomingMessageActions.STARTCELL]: NativeEditorReducerFunc<ICell>;
Expand All @@ -90,4 +78,5 @@ export class INativeEditorActionMapping {
public [IncomingMessageActions.GETCSSRESPONSE]: NativeEditorReducerFunc<IGetCssResponse>;
public [IncomingMessageActions.MONACOREADY]: NativeEditorReducerFunc<never | undefined>;
public [IncomingMessageActions.GETMONACOTHEMERESPONSE]: NativeEditorReducerFunc<IGetMonacoThemeResponse>;
public [IncomingMessageActions.UPDATEKERNEL]: NativeEditorReducerFunc<IKernel>;
}
Loading