Skip to content

Commit e03f447

Browse files
Disable run-by-line and continue buttons when actively running by line (#12170)
1 parent 3a2d29c commit e03f447

File tree

15 files changed

+143
-25
lines changed

15 files changed

+143
-25
lines changed

news/2 Fixes/12169.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Disable run-by-line and continue buttons in run by line mode when running.

src/client/datascience/interactive-common/interactiveWindowTypes.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
'use strict';
44
import * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api';
55
import { Uri } from 'vscode';
6-
import { IServerState } from '../../../datascience-ui/interactive-common/mainState';
6+
import { DebugState, IServerState } from '../../../datascience-ui/interactive-common/mainState';
77

88
import type { KernelMessage } from '@jupyterlab/services';
99
import { DebugProtocol } from 'vscode-debugprotocol';
@@ -135,6 +135,7 @@ export enum InteractiveWindowMessages {
135135
ShowContinue = 'show_continue',
136136
ShowBreak = 'show_break',
137137
ShowingIp = 'showing_ip',
138+
DebugStateChange = 'debug_state_change',
138139
KernelIdle = 'kernel_idle'
139140
}
140141

@@ -341,6 +342,11 @@ export interface IRenderComplete {
341342
ids: string[];
342343
}
343344

345+
export interface IDebugStateChange {
346+
oldState: DebugState;
347+
newState: DebugState;
348+
}
349+
344350
export interface IFocusedCellEditor {
345351
cellId: string;
346352
}
@@ -645,4 +651,5 @@ export class IInteractiveWindowMapping {
645651
public [InteractiveWindowMessages.Step]: never | undefined;
646652
public [InteractiveWindowMessages.ShowingIp]: never | undefined;
647653
public [InteractiveWindowMessages.KernelIdle]: never | undefined;
654+
public [InteractiveWindowMessages.DebugStateChange]: IDebugStateChange;
648655
}

src/client/datascience/interactive-common/synchronization.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ const messageWithMessageTypes: MessageMapping<IInteractiveWindowMapping> & Messa
106106
[InteractiveWindowMessages.CollapseAll]: MessageType.syncWithLiveShare,
107107
[InteractiveWindowMessages.Continue]: MessageType.other,
108108
[InteractiveWindowMessages.CopyCodeCell]: MessageType.other,
109+
[InteractiveWindowMessages.DebugStateChange]: MessageType.other,
109110
[InteractiveWindowMessages.DeleteAllCells]: MessageType.syncAcrossSameNotebooks | MessageType.syncWithLiveShare,
110111
[InteractiveWindowMessages.DoSave]: MessageType.other,
111112
[InteractiveWindowMessages.ExecutionRendered]: MessageType.other,

src/client/datascience/interactive-ipynb/nativeEditorRunByLineListener.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,13 @@ export class NativeEditorRunByLineListener
105105

106106
private async handleStep() {
107107
// User issued a step command.
108+
this.postEmitter.fire({ message: InteractiveWindowMessages.ShowContinue, payload: undefined });
108109
return this.debugService.step();
109110
}
110111

111112
private async handleContinue() {
112113
// User issued a continue command
114+
this.postEmitter.fire({ message: InteractiveWindowMessages.ShowContinue, payload: undefined });
113115
return this.debugService.continue();
114116
}
115117

src/datascience-ui/interactive-common/mainState.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ export enum CursorPos {
2424
Current
2525
}
2626

27+
// The state we are in for run by line debugging
28+
export enum DebugState {
29+
Break,
30+
Design,
31+
Run
32+
}
33+
34+
export function activeDebugState(state: DebugState): boolean {
35+
return state === DebugState.Break || state === DebugState.Run;
36+
}
37+
2738
export interface ICellViewModel {
2839
cell: ICell;
2940
inputBlockShow: boolean;
@@ -43,7 +54,7 @@ export interface ICellViewModel {
4354
runDuringDebug?: boolean;
4455
codeVersion?: number;
4556
uiSideError?: string;
46-
runningByLine: boolean;
57+
runningByLine: DebugState;
4758
currentStack?: DebugProtocol.StackFrame[];
4859
}
4960

@@ -212,7 +223,7 @@ export function createEditableCellVM(executionCount: number): ICellViewModel {
212223
cursorPos: CursorPos.Current,
213224
hasBeenRun: false,
214225
scrollCount: 0,
215-
runningByLine: false
226+
runningByLine: DebugState.Design
216227
};
217228
}
218229

@@ -266,7 +277,7 @@ export function createCellVM(
266277
hasBeenRun: false,
267278
scrollCount: 0,
268279
runDuringDebug,
269-
runningByLine: false
280+
runningByLine: DebugState.Design
270281
};
271282

272283
// Update the input text

src/datascience-ui/interactive-common/redux/reducers/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const cloneDeep = require('lodash/cloneDeep');
88
import { CellState, ICell, IDataScienceExtraSettings } from '../../../../client/datascience/types';
99
import { arePathsSame } from '../../../react-common/arePathsSame';
1010
import { detectBaseTheme } from '../../../react-common/themeDetector';
11-
import { ICellViewModel, IMainState } from '../../mainState';
11+
import { DebugState, ICellViewModel, IMainState } from '../../mainState';
1212
import { CommonActionType, CommonReducerArg } from './types';
1313

1414
const StackLimit = 10;
@@ -96,7 +96,7 @@ export namespace Helpers {
9696
source: newVMs[index].cell.data.source
9797
}
9898
},
99-
runningByLine: finished ? false : newVMs[index].runningByLine
99+
runningByLine: finished ? DebugState.Design : newVMs[index].runningByLine
100100
};
101101
newVMs[index] = newVM;
102102

src/datascience-ui/interactive-common/redux/store.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ import { MessageType } from '../../../client/datascience/interactive-common/sync
1414
import { BaseReduxActionPayload } from '../../../client/datascience/interactive-common/types';
1515
import { CssMessages } from '../../../client/datascience/messages';
1616
import { CellState } from '../../../client/datascience/types';
17-
import { getSelectedAndFocusedInfo, IMainState, ServerStatus } from '../../interactive-common/mainState';
17+
import {
18+
activeDebugState,
19+
DebugState,
20+
getSelectedAndFocusedInfo,
21+
ICellViewModel,
22+
IMainState,
23+
ServerStatus
24+
} from '../../interactive-common/mainState';
1825
import { getLocString } from '../../react-common/locReactSide';
1926
import { PostOffice } from '../../react-common/postOffice';
2027
import { combineReducers, createQueueableActionMiddleware, QueuableAction } from '../../react-common/reduxUtils';
@@ -240,13 +247,27 @@ function createTestMiddleware(): Redux.Middleware<{}, IStore> {
240247
sendMessage(InteractiveWindowMessages.KernelIdle);
241248
}
242249

250+
// Debug state changing
251+
const oldState = getDebugState(prevState.main.cellVMs);
252+
const newState = getDebugState(afterState.main.cellVMs);
253+
if (oldState !== newState) {
254+
sendMessage(InteractiveWindowMessages.DebugStateChange, { oldState, newState });
255+
}
256+
243257
if (action.type !== 'action.postOutgoingMessage') {
244258
sendMessage(`DISPATCHED_ACTION_${action.type}`, {});
245259
}
246260
return res;
247261
};
248262
}
249263

264+
// Find the debug state for cell view models
265+
function getDebugState(vms: ICellViewModel[]): DebugState {
266+
const firstNonDesign = vms.find((cvm) => activeDebugState(cvm.runningByLine));
267+
268+
return firstNonDesign ? firstNonDesign.runningByLine : DebugState.Design;
269+
}
270+
250271
function createMiddleWare(testMode: boolean): Redux.Middleware<{}, IStore>[] {
251272
// Create the middleware that modifies actions to queue new actions
252273
const queueableActions = createQueueableActionMiddleware();

src/datascience-ui/native-editor/nativeCell.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { CellInput } from '../interactive-common/cellInput';
2121
import { CellOutput } from '../interactive-common/cellOutput';
2222
import { ExecutionCount } from '../interactive-common/executionCount';
2323
import { InformationMessages } from '../interactive-common/informationMessages';
24-
import { CursorPos, ICellViewModel, IFont } from '../interactive-common/mainState';
24+
import { activeDebugState, CursorPos, DebugState, ICellViewModel, IFont } from '../interactive-common/mainState';
2525
import { getOSType } from '../react-common/constants';
2626
import { IKeyboardEvent } from '../react-common/event';
2727
import { Image, ImageName } from '../react-common/image';
@@ -61,7 +61,7 @@ interface INativeCellBaseProps {
6161
focusPending: number;
6262
busy: boolean;
6363
useCustomEditorApi: boolean;
64-
runningByLine: boolean;
64+
runningByLine: DebugState;
6565
supportsRunByLine: boolean;
6666
}
6767

@@ -611,7 +611,7 @@ export class NativeCell extends React.Component<INativeCellProps> {
611611
};
612612
const toolbarClassName = this.props.cellVM.cell.data.cell_type === 'code' ? '' : 'markdown-toolbar';
613613

614-
if (this.props.runningByLine && !this.isMarkdownCell()) {
614+
if (activeDebugState(this.props.runningByLine) && !this.isMarkdownCell()) {
615615
return (
616616
<div className={toolbarClassName}>
617617
<div className="native-editor-celltoolbar-middle">
@@ -620,7 +620,7 @@ export class NativeCell extends React.Component<INativeCellProps> {
620620
onClick={cont}
621621
tooltip={getLocString('DataScience.continueRunByLine', 'Stop')}
622622
hidden={this.isMarkdownCell()}
623-
disabled={this.props.busy}
623+
disabled={this.props.busy || this.props.runningByLine === DebugState.Run}
624624
>
625625
<div className="codicon codicon-button">{CodIcon.Stop}</div>
626626
</ImageButton>
@@ -629,7 +629,7 @@ export class NativeCell extends React.Component<INativeCellProps> {
629629
onClick={step}
630630
tooltip={getLocString('DataScience.step', 'Run next line')}
631631
hidden={this.isMarkdownCell()}
632-
disabled={this.props.busy}
632+
disabled={this.props.busy || this.props.runningByLine === DebugState.Run}
633633
>
634634
<Image
635635
baseTheme={this.props.baseTheme}

src/datascience-ui/native-editor/nativeEditor.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ import { NativeKeyboardCommandTelemetry, NativeMouseCommandTelemetry } from '../
88
import { buildSettingsCss } from '../interactive-common/buildSettingsCss';
99
import { ContentPanel, IContentPanelProps } from '../interactive-common/contentPanel';
1010
import { handleLinkClick } from '../interactive-common/handlers';
11-
import { getSelectedAndFocusedInfo, ICellViewModel, IMainState } from '../interactive-common/mainState';
11+
import {
12+
activeDebugState,
13+
DebugState,
14+
getSelectedAndFocusedInfo,
15+
ICellViewModel,
16+
IMainState
17+
} from '../interactive-common/mainState';
1218
import { IMainWithVariables, IStore } from '../interactive-common/redux/store';
1319
import { IVariablePanelProps, VariablePanel } from '../interactive-common/variablePanel';
1420
import { getOSType } from '../react-common/constants';
@@ -225,7 +231,8 @@ ${buildSettingsCss(this.props.settings)}`}</style>
225231

226232
case 'F10':
227233
if (this.props.debugging) {
228-
const debuggingCell = this.props.cellVMs.find((cvm) => cvm.runningByLine);
234+
// Only allow step if debugging in break mode
235+
const debuggingCell = this.props.cellVMs.find((cvm) => cvm.runningByLine === DebugState.Break);
229236
if (debuggingCell) {
230237
this.props.step(debuggingCell.cell.id);
231238
}
@@ -234,7 +241,8 @@ ${buildSettingsCss(this.props.settings)}`}</style>
234241
break;
235242
case 'F5':
236243
if (this.props.debugging) {
237-
const debuggingCell = this.props.cellVMs.find((cvm) => cvm.runningByLine);
244+
// Only allow continue if debugging in break mode
245+
const debuggingCell = this.props.cellVMs.find((cvm) => cvm.runningByLine === DebugState.Break);
238246
if (debuggingCell) {
239247
this.props.continue(debuggingCell.cell.id);
240248
}
@@ -299,7 +307,7 @@ ${buildSettingsCss(this.props.settings)}`}</style>
299307
) : null;
300308

301309
const otherCellRunningByLine = this.props.cellVMs.find(
302-
(cvm) => cvm.runningByLine && cvm.cell.id !== cellVM.cell.id
310+
(cvm) => activeDebugState(cvm.runningByLine) && cvm.cell.id !== cellVM.cell.id
303311
);
304312
const maxOutputSize = this.props.settings.maxOutputSize;
305313
const outputSizeLimit = 10000;

src/datascience-ui/native-editor/redux/reducers/creation.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
createCellVM,
1515
createEmptyCell,
1616
CursorPos,
17+
DebugState,
1718
extractInputText,
1819
getSelectedAndFocusedInfo,
1920
ICellViewModel,
@@ -191,7 +192,7 @@ export namespace Creation {
191192
cursorPos: CursorPos.Current,
192193
hasBeenRun: false,
193194
scrollCount: 0,
194-
runningByLine: false
195+
runningByLine: DebugState.Design
195196
};
196197

197198
Transfer.postModelRemoveAll(arg, newVM.cell.id);
@@ -247,7 +248,7 @@ export namespace Creation {
247248
cursorPos: CursorPos.Current,
248249
hasBeenRun: false,
249250
scrollCount: 0,
250-
runningByLine: false
251+
runningByLine: DebugState.Design
251252
};
252253

253254
// Send messages to other side to indicate the new add

0 commit comments

Comments
 (0)