Skip to content

Commit 92b221e

Browse files
committed
Clear variables when restarting regardless if visible or not (#10117)
1 parent 880e806 commit 92b221e

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

news/2 Fixes/9991.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clear variables in notebooks and interactive-window when restarting.

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,12 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {
327327
return this.setDirty();
328328
}
329329

330-
protected addSysInfo(_reason: SysInfoReason): Promise<void> {
330+
protected addSysInfo(reason: SysInfoReason): Promise<void> {
331+
// We need to send a message when restarting
332+
if (reason === SysInfoReason.Restart || reason === SysInfoReason.New) {
333+
this.postMessage(InteractiveWindowMessages.RestartKernel).ignoreErrors();
334+
}
335+
331336
// These are not supported.
332337
return Promise.resolve();
333338
}

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,21 @@ function handleResponse(arg: VariableReducerArg<IJupyterVariablesResponse>): IVa
106106
}
107107

108108
function handleRestarted(arg: VariableReducerArg): IVariableState {
109-
// If the variables are visible, refresh them
110-
if (arg.prevState.visible) {
111-
const result = handleRequest({ ...arg, payload: { executionCount: 0, sortColumn: 'name', sortAscending: true, startIndex: 0, pageSize: arg.prevState.pageSize } });
112-
return {
113-
...result,
114-
currentExecutionCount: 0,
115-
variables: []
116-
};
117-
}
118-
return arg.prevState;
109+
const result = handleRequest({
110+
...arg,
111+
payload: {
112+
executionCount: 0,
113+
sortColumn: 'name',
114+
sortAscending: true,
115+
startIndex: 0,
116+
pageSize: arg.prevState.pageSize
117+
}
118+
});
119+
return {
120+
...result,
121+
currentExecutionCount: 0,
122+
variables: []
123+
};
119124
}
120125

121126
function handleFinishCell(arg: VariableReducerArg<ICell>): IVariableState {

0 commit comments

Comments
 (0)