Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
211 changes: 107 additions & 104 deletions src/client/datascience/interactive-common/synchronization.ts

Large diffs are not rendered by default.

42 changes: 19 additions & 23 deletions src/datascience-ui/history-react/redux/reducers/creation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Identifiers } from '../../../../client/datascience/constants';
import { InteractiveWindowMessages } from '../../../../client/datascience/interactive-common/interactiveWindowTypes';
import { ICell, IDataScienceExtraSettings } from '../../../../client/datascience/types';
import { createCellVM, extractInputText, ICellViewModel, IMainState } from '../../../interactive-common/mainState';
import { createPostableAction } from '../../../interactive-common/redux/helpers';
import { postActionToExtension } from '../../../interactive-common/redux/helpers';
import { Helpers } from '../../../interactive-common/redux/reducers/helpers';
import { IAddCellAction, ICellAction } from '../../../interactive-common/redux/reducers/types';
import { InteractiveReducerArg } from '../mapping';
Expand Down Expand Up @@ -85,17 +85,15 @@ export namespace Creation {
const cellVM = result.cellVMs[result.cellVMs.length - 1];

// We're adding a new cell here. Tell the intellisense engine we have a new cell
arg.queueAction(
createPostableAction(InteractiveWindowMessages.UpdateModel, {
source: 'user',
kind: 'add',
oldDirty: arg.prevState.dirty,
newDirty: true,
cell: cellVM.cell,
fullText: extractInputText(cellVM, result.settings),
currentText: cellVM.inputBlockText
})
);
postActionToExtension(arg, InteractiveWindowMessages.UpdateModel, {
source: 'user',
kind: 'add',
oldDirty: arg.prevState.dirty,
newDirty: true,
cell: cellVM.cell,
fullText: extractInputText(cellVM, result.settings),
currentText: cellVM.inputBlockText
});
}

return result;
Expand All @@ -119,7 +117,7 @@ export namespace Creation {

export function deleteAllCells(arg: InteractiveReducerArg<IAddCellAction>): IMainState {
// Send messages to other side to indicate the deletes
arg.queueAction(createPostableAction(InteractiveWindowMessages.DeleteAllCells));
postActionToExtension(arg, InteractiveWindowMessages.DeleteAllCells);

return {
...arg.prevState,
Expand All @@ -132,16 +130,14 @@ export namespace Creation {
const index = arg.prevState.cellVMs.findIndex(c => c.cell.id === arg.payload.data.cellId);
if (index >= 0 && arg.payload.data.cellId) {
// Send messages to other side to indicate the delete
arg.queueAction(
createPostableAction(InteractiveWindowMessages.UpdateModel, {
source: 'user',
kind: 'remove',
index,
oldDirty: arg.prevState.dirty,
newDirty: true,
cell: arg.prevState.cellVMs[index].cell
})
);
postActionToExtension(arg, InteractiveWindowMessages.UpdateModel, {
source: 'user',
kind: 'remove',
index,
oldDirty: arg.prevState.dirty,
newDirty: true,
cell: arg.prevState.cellVMs[index].cell
});

const newVMs = arg.prevState.cellVMs.filter((_c, i) => i !== index);
return {
Expand Down
6 changes: 3 additions & 3 deletions src/datascience-ui/history-react/redux/reducers/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IScrollToCell } from '../../../../client/datascience/interactive-common
import { CssMessages } from '../../../../client/datascience/messages';
import { IDataScienceExtraSettings } from '../../../../client/datascience/types';
import { IMainState } from '../../../interactive-common/mainState';
import { createPostableAction } from '../../../interactive-common/redux/helpers';
import { postActionToExtension } from '../../../interactive-common/redux/helpers';
import { Helpers } from '../../../interactive-common/redux/reducers/helpers';
import { ICellAction, IScrollAction } from '../../../interactive-common/redux/reducers/types';
import { computeEditorOptions } from '../../../react-common/settingsReactSide';
Expand Down Expand Up @@ -62,8 +62,8 @@ export namespace Effects {
if (newSettings && newSettings.extraSettings && newSettings.extraSettings.theme !== arg.prevState.vscodeThemeName) {
const knownDark = Helpers.computeKnownDark(newSettings);
// User changed the current theme. Rerender
arg.queueAction(createPostableAction(CssMessages.GetCssRequest, { isDark: knownDark }));
arg.queueAction(createPostableAction(CssMessages.GetMonacoThemeRequest, { isDark: knownDark }));
postActionToExtension(arg, CssMessages.GetCssRequest, { isDark: knownDark });
postActionToExtension(arg, CssMessages.GetMonacoThemeRequest, { isDark: knownDark });
}

// Update our input cell state if the user changed this setting
Expand Down
8 changes: 4 additions & 4 deletions src/datascience-ui/history-react/redux/reducers/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { CellState } from '../../../../client/datascience/types';
import { generateMarkdownFromCodeLines } from '../../../common';
import { createCellFrom } from '../../../common/cellFactory';
import { createCellVM, IMainState } from '../../../interactive-common/mainState';
import { createPostableAction } from '../../../interactive-common/redux/helpers';
import { postActionToExtension } from '../../../interactive-common/redux/helpers';
import { Helpers } from '../../../interactive-common/redux/reducers/helpers';
import { ICodeAction } from '../../../interactive-common/redux/reducers/types';
import { InteractiveReducerArg } from '../mapping';
Expand All @@ -24,7 +24,7 @@ export namespace Execution {
const cells = arg.prevState.undoStack[arg.prevState.undoStack.length - 1];
const undoStack = arg.prevState.undoStack.slice(0, arg.prevState.undoStack.length - 1);
const redoStack = Helpers.pushStack(arg.prevState.redoStack, arg.prevState.cellVMs);
arg.queueAction(createPostableAction(InteractiveWindowMessages.Undo));
postActionToExtension(arg, InteractiveWindowMessages.Undo);
return {
...arg.prevState,
cellVMs: cells,
Expand All @@ -43,7 +43,7 @@ export namespace Execution {
const cells = arg.prevState.redoStack[arg.prevState.redoStack.length - 1];
const redoStack = arg.prevState.redoStack.slice(0, arg.prevState.redoStack.length - 1);
const undoStack = Helpers.pushStack(arg.prevState.undoStack, arg.prevState.cellVMs);
arg.queueAction(createPostableAction(InteractiveWindowMessages.Redo));
postActionToExtension(arg, InteractiveWindowMessages.Redo);
return {
...arg.prevState,
cellVMs: cells,
Expand Down Expand Up @@ -107,7 +107,7 @@ export namespace Execution {

// Send a message to execute this code if necessary.
if (newCell.cell.state !== CellState.finished) {
arg.queueAction(createPostableAction(InteractiveWindowMessages.SubmitNewCell, { code: arg.payload.data.code, id: newCell.cell.id }));
postActionToExtension(arg, InteractiveWindowMessages.SubmitNewCell, { code: arg.payload.data.code, id: newCell.cell.id });
}

// Stick in a new cell at the bottom that's editable and update our state
Expand Down
28 changes: 23 additions & 5 deletions src/datascience-ui/interactive-common/redux/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as Redux from 'redux';
import { IInteractiveWindowMapping, InteractiveWindowMessages } from '../../../client/datascience/interactive-common/interactiveWindowTypes';
import { BaseReduxActionPayload } from '../../../client/datascience/interactive-common/types';
import { CssMessages, SharedMessages } from '../../../client/datascience/messages';
import { QueueAnotherFunc } from '../../react-common/reduxUtils';
import { CommonAction, CommonActionType, CommonActionTypeMapping } from './reducers/types';

const AllowedMessages = [...Object.values(InteractiveWindowMessages), ...Object.values(CssMessages), ...Object.values(SharedMessages), ...Object.values(CommonActionType)];
Expand All @@ -26,14 +27,31 @@ export function createIncomingAction(type: CommonActionType | InteractiveWindowM
return { type, payload: { messageDirection: 'incoming', data: undefined } };
}

// Actions created from messages
export function createPostableAction<M extends IInteractiveWindowMapping, T extends keyof M = keyof M>(message: T, payload?: M[T]): Redux.AnyAction {
const newPayload: BaseReduxActionPayload<M[T]> = ({
type ReducerArg = {
// tslint:disable-next-line: no-any
queueAction: QueueAnotherFunc<any>;
// tslint:disable-next-line: no-any
payload?: BaseReduxActionPayload<any>;
};
/**
* Post a message to the extension (via dispatcher actions).
*/
export function postActionToExtension<K, M extends IInteractiveWindowMapping, T extends keyof M = keyof M>(originalReducerArg: ReducerArg, message: T, payload?: M[T]): void;
/**
* Post a message to the extension (via dispatcher actions).
*/
// tslint:disable-next-line: unified-signatures
export function postActionToExtension<K, M extends IInteractiveWindowMapping, T extends keyof M = keyof M>(originalReducerArg: ReducerArg, message: T, payload?: M[T]): void;
// tslint:disable-next-line: no-any
export function postActionToExtension(originalReducerArg: ReducerArg, message: any, payload?: any) {
// tslint:disable-next-line: no-any
const newPayload: BaseReduxActionPayload<any> = ({
data: payload,
messageDirection: 'outgoing'
// tslint:disable-next-line: no-any
} as any) as BaseReduxActionPayload<M[T]>;
return { type: CommonActionType.PostOutgoingMessage, payload: { payload: newPayload, type: message } };
} as any) as BaseReduxActionPayload<any>;
const action = { type: CommonActionType.PostOutgoingMessage, payload: { payload: newPayload, type: message } };
originalReducerArg.queueAction(action);
}
export function unwrapPostableAction(action: Redux.AnyAction): { type: keyof IInteractiveWindowMapping; payload?: BaseReduxActionPayload<{}> } {
// Unwrap the payload that was created in `createPostableAction`.
Expand Down
10 changes: 5 additions & 5 deletions src/datascience-ui/interactive-common/redux/reducers/kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
import { InteractiveWindowMessages } from '../../../../client/datascience/interactive-common/interactiveWindowTypes';
import { CellState } from '../../../../client/datascience/types';
import { IMainState, IServerState } from '../../mainState';
import { createPostableAction } from '../helpers';
import { postActionToExtension } from '../helpers';
import { CommonActionType, CommonReducerArg } from './types';

export namespace Kernel {
// tslint:disable-next-line: no-any
export function selectKernel(arg: CommonReducerArg<CommonActionType | InteractiveWindowMessages, IServerState | undefined>): IMainState {
arg.queueAction(createPostableAction(InteractiveWindowMessages.SelectKernel));
postActionToExtension(arg, InteractiveWindowMessages.SelectKernel);

return arg.prevState;
}
export function selectJupyterURI(arg: CommonReducerArg): IMainState {
arg.queueAction(createPostableAction(InteractiveWindowMessages.SelectJupyterServer));
postActionToExtension(arg, InteractiveWindowMessages.SelectJupyterServer);

return arg.prevState;
}
export function restartKernel(arg: CommonReducerArg): IMainState {
arg.queueAction(createPostableAction(InteractiveWindowMessages.RestartKernel));
postActionToExtension(arg, InteractiveWindowMessages.RestartKernel);

// Set busy until kernel is restarted
return {
Expand All @@ -30,7 +30,7 @@ export namespace Kernel {
}

export function interruptKernel(arg: CommonReducerArg): IMainState {
arg.queueAction(createPostableAction(InteractiveWindowMessages.Interrupt));
postActionToExtension(arg, InteractiveWindowMessages.Interrupt);

// Set busy until kernel is finished interrupting
return {
Expand Down
38 changes: 19 additions & 19 deletions src/datascience-ui/interactive-common/redux/reducers/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { IEditorContentChange, InteractiveWindowMessages, NotebookModelChange }
import { CssMessages } from '../../../../client/datascience/messages';
import { ICell } from '../../../../client/datascience/types';
import { extractInputText, getSelectedAndFocusedInfo, IMainState } from '../../mainState';
import { createPostableAction } from '../helpers';
import { postActionToExtension } from '../helpers';
import { Helpers } from './helpers';
import { CommonActionType, CommonReducerArg, ICellAction, IEditCellAction, ILinkClickAction, ISendCommandAction, IShowDataViewerAction } from './types';

// These are all reducers that don't actually change state. They merely dispatch a message to the other side.
export namespace Transfer {
export function exportCells(arg: CommonReducerArg): IMainState {
const cellContents = arg.prevState.cellVMs.map(v => v.cell);
arg.queueAction(createPostableAction(InteractiveWindowMessages.Export, cellContents));
postActionToExtension(arg, InteractiveWindowMessages.Export, cellContents);

// Indicate busy
return {
Expand All @@ -27,46 +27,46 @@ export namespace Transfer {
// Note: this is assuming editor contents have already been saved. That should happen as a result of focus change

// Actually waiting for save results before marking as not dirty, so don't do it here.
arg.queueAction(createPostableAction(InteractiveWindowMessages.SaveAll, { cells: arg.prevState.cellVMs.map(cvm => cvm.cell) }));
postActionToExtension(arg, InteractiveWindowMessages.SaveAll, { cells: arg.prevState.cellVMs.map(cvm => cvm.cell) });
return arg.prevState;
}

export function showDataViewer(arg: CommonReducerArg<CommonActionType, IShowDataViewerAction>): IMainState {
arg.queueAction(createPostableAction(InteractiveWindowMessages.ShowDataViewer, { variable: arg.payload.data.variable, columnSize: arg.payload.data.columnSize }));
postActionToExtension(arg, InteractiveWindowMessages.ShowDataViewer, { variable: arg.payload.data.variable, columnSize: arg.payload.data.columnSize });
return arg.prevState;
}

export function sendCommand(arg: CommonReducerArg<CommonActionType, ISendCommandAction>): IMainState {
arg.queueAction(createPostableAction(InteractiveWindowMessages.NativeCommand, { command: arg.payload.data.command, source: arg.payload.data.commandType }));
postActionToExtension(arg, InteractiveWindowMessages.NativeCommand, { command: arg.payload.data.command, source: arg.payload.data.commandType });
return arg.prevState;
}

export function showPlot(arg: CommonReducerArg<CommonActionType | InteractiveWindowMessages, string | undefined>): IMainState {
if (arg.payload.data) {
arg.queueAction(createPostableAction(InteractiveWindowMessages.ShowPlot, arg.payload.data));
postActionToExtension(arg, InteractiveWindowMessages.ShowPlot, arg.payload.data);
}
return arg.prevState;
}

export function linkClick(arg: CommonReducerArg<CommonActionType, ILinkClickAction>): IMainState {
if (arg.payload.data.href.startsWith('data:image/png')) {
arg.queueAction(createPostableAction(InteractiveWindowMessages.SavePng, arg.payload.data.href));
postActionToExtension(arg, InteractiveWindowMessages.SavePng, arg.payload.data.href);
} else {
arg.queueAction(createPostableAction(InteractiveWindowMessages.OpenLink, arg.payload.data.href));
postActionToExtension(arg, InteractiveWindowMessages.OpenLink, arg.payload.data.href);
}
return arg.prevState;
}

export function getAllCells(arg: CommonReducerArg): IMainState {
const cells = arg.prevState.cellVMs.map(c => c.cell);
arg.queueAction(createPostableAction(InteractiveWindowMessages.ReturnAllCells, cells));
postActionToExtension(arg, InteractiveWindowMessages.ReturnAllCells, cells);
return arg.prevState;
}

export function gotoCell(arg: CommonReducerArg<CommonActionType, ICellAction>): IMainState {
const cellVM = arg.prevState.cellVMs.find(c => c.cell.id === arg.payload.data.cellId);
if (cellVM && cellVM.cell.data.cell_type === 'code') {
arg.queueAction(createPostableAction(InteractiveWindowMessages.GotoCodeCell, { file: cellVM.cell.file, line: cellVM.cell.line }));
postActionToExtension(arg, InteractiveWindowMessages.GotoCodeCell, { file: cellVM.cell.file, line: cellVM.cell.line });
}
return arg.prevState;
}
Expand All @@ -79,7 +79,7 @@ export namespace Transfer {

// Send a message to the other side to jump to a particular cell
if (cellVM) {
arg.queueAction(createPostableAction(InteractiveWindowMessages.CopyCodeCell, { source: extractInputText(cellVM, arg.prevState.settings) }));
postActionToExtension(arg, InteractiveWindowMessages.CopyCodeCell, { source: extractInputText(cellVM, arg.prevState.settings) });
}

return arg.prevState;
Expand All @@ -88,13 +88,13 @@ export namespace Transfer {
export function gather(arg: CommonReducerArg<CommonActionType, ICellAction>): IMainState {
const cellVM = arg.prevState.cellVMs.find(c => c.cell.id === arg.payload.data.cellId);
if (cellVM) {
arg.queueAction(createPostableAction(InteractiveWindowMessages.GatherCodeRequest, cellVM.cell));
postActionToExtension(arg, InteractiveWindowMessages.GatherCodeRequest, cellVM.cell);
}
return arg.prevState;
}

function postModelUpdate<T>(arg: CommonReducerArg<CommonActionType, T>, update: NotebookModelChange) {
arg.queueAction(createPostableAction(InteractiveWindowMessages.UpdateModel, update));
postActionToExtension(arg, InteractiveWindowMessages.UpdateModel, update);
}

export function postModelEdit<T>(arg: CommonReducerArg<CommonActionType, T>, forward: IEditorContentChange[], reverse: IEditorContentChange[], id: string) {
Expand Down Expand Up @@ -199,16 +199,16 @@ export namespace Transfer {

export function started(arg: CommonReducerArg): IMainState {
// Send all of our initial requests
arg.queueAction(createPostableAction(InteractiveWindowMessages.Started));
arg.queueAction(createPostableAction(CssMessages.GetCssRequest, { isDark: arg.prevState.baseTheme !== 'vscode-light' }));
arg.queueAction(createPostableAction(CssMessages.GetMonacoThemeRequest, { isDark: arg.prevState.baseTheme !== 'vscode-light' }));
arg.queueAction(createPostableAction(InteractiveWindowMessages.LoadOnigasmAssemblyRequest));
arg.queueAction(createPostableAction(InteractiveWindowMessages.LoadTmLanguageRequest));
postActionToExtension(arg, InteractiveWindowMessages.Started);
postActionToExtension(arg, CssMessages.GetCssRequest, { isDark: arg.prevState.baseTheme !== 'vscode-light' });
postActionToExtension(arg, CssMessages.GetMonacoThemeRequest, { isDark: arg.prevState.baseTheme !== 'vscode-light' });
postActionToExtension(arg, InteractiveWindowMessages.LoadOnigasmAssemblyRequest);
postActionToExtension(arg, InteractiveWindowMessages.LoadTmLanguageRequest);
return arg.prevState;
}

export function loadedAllCells(arg: CommonReducerArg): IMainState {
arg.queueAction(createPostableAction(InteractiveWindowMessages.LoadAllCellsComplete, { cells: arg.prevState.cellVMs.map(c => c.cell) }));
postActionToExtension(arg, InteractiveWindowMessages.LoadAllCellsComplete, { cells: arg.prevState.cellVMs.map(c => c.cell) });
return arg.prevState;
}
}
Loading