diff --git a/news/2 Fixes/9991.md b/news/2 Fixes/9991.md new file mode 100644 index 000000000000..1296552cc995 --- /dev/null +++ b/news/2 Fixes/9991.md @@ -0,0 +1 @@ +Clear variables in notebooks and interactive-window when restarting. \ No newline at end of file diff --git a/src/client/datascience/interactive-ipynb/nativeEditor.ts b/src/client/datascience/interactive-ipynb/nativeEditor.ts index a879a576d42f..af47f2ef3eaa 100644 --- a/src/client/datascience/interactive-ipynb/nativeEditor.ts +++ b/src/client/datascience/interactive-ipynb/nativeEditor.ts @@ -354,7 +354,12 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor { return this.setDirty(); } - protected addSysInfo(_reason: SysInfoReason): Promise { + protected addSysInfo(reason: SysInfoReason): Promise { + // We need to send a message when restarting + if (reason === SysInfoReason.Restart || reason === SysInfoReason.New) { + this.postMessage(InteractiveWindowMessages.RestartKernel).ignoreErrors(); + } + // These are not supported. return Promise.resolve(); } diff --git a/src/datascience-ui/interactive-common/redux/reducers/variables.ts b/src/datascience-ui/interactive-common/redux/reducers/variables.ts index 83a11a3b2d8e..840655a4c122 100644 --- a/src/datascience-ui/interactive-common/redux/reducers/variables.ts +++ b/src/datascience-ui/interactive-common/redux/reducers/variables.ts @@ -118,25 +118,21 @@ function handleResponse(arg: VariableReducerArg): IVa } function handleRestarted(arg: VariableReducerArg): IVariableState { - // If the variables are visible, refresh them - if (arg.prevState.visible) { - const result = handleRequest({ - ...arg, - payload: { - executionCount: 0, - sortColumn: 'name', - sortAscending: true, - startIndex: 0, - pageSize: arg.prevState.pageSize - } - }); - return { - ...result, - currentExecutionCount: 0, - variables: [] - }; - } - return arg.prevState; + const result = handleRequest({ + ...arg, + payload: { + executionCount: 0, + sortColumn: 'name', + sortAscending: true, + startIndex: 0, + pageSize: arg.prevState.pageSize + } + }); + return { + ...result, + currentExecutionCount: 0, + variables: [] + }; } function handleFinishCell(arg: VariableReducerArg): IVariableState {