Skip to content

Commit 077c42a

Browse files
authored
Clear variables when restarting regardless if visible or not (#10117)
1 parent 6b6b959 commit 077c42a

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
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
@@ -355,7 +355,12 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {
355355
return this.setDirty();
356356
}
357357

358-
protected addSysInfo(_reason: SysInfoReason): Promise<void> {
358+
protected addSysInfo(reason: SysInfoReason): Promise<void> {
359+
// We need to send a message when restarting
360+
if (reason === SysInfoReason.Restart || reason === SysInfoReason.New) {
361+
this.postMessage(InteractiveWindowMessages.RestartKernel).ignoreErrors();
362+
}
363+
359364
// These are not supported.
360365
return Promise.resolve();
361366
}

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

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,21 @@ function handleResponse(arg: VariableReducerArg<IJupyterVariablesResponse>): IVa
118118
}
119119

120120
function handleRestarted(arg: VariableReducerArg): IVariableState {
121-
// If the variables are visible, refresh them
122-
if (arg.prevState.visible) {
123-
const result = handleRequest({
124-
...arg,
125-
payload: {
126-
executionCount: 0,
127-
sortColumn: 'name',
128-
sortAscending: true,
129-
startIndex: 0,
130-
pageSize: arg.prevState.pageSize
131-
}
132-
});
133-
return {
134-
...result,
135-
currentExecutionCount: 0,
136-
variables: []
137-
};
138-
}
139-
return arg.prevState;
121+
const result = handleRequest({
122+
...arg,
123+
payload: {
124+
executionCount: 0,
125+
sortColumn: 'name',
126+
sortAscending: true,
127+
startIndex: 0,
128+
pageSize: arg.prevState.pageSize
129+
}
130+
});
131+
return {
132+
...result,
133+
currentExecutionCount: 0,
134+
variables: []
135+
};
140136
}
141137

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

0 commit comments

Comments
 (0)