From 981e4f067fa73f8e8caba153b1829db57d117619 Mon Sep 17 00:00:00 2001 From: amunger Date: Fri, 15 Nov 2024 16:13:57 -0800 Subject: [PATCH] only set notebook open context key if it uses a jupyter kernel --- package.json | 2 +- package.nls.json | 4 +-- src/standalone/context/activeEditorContext.ts | 33 +++++++------------ 3 files changed, 15 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 5660dd188c7..b85ee4bd90a 100644 --- a/package.json +++ b/package.json @@ -2020,7 +2020,7 @@ { "type": "webview", "id": "jupyterViewVariables", - "name": "Variables", + "name": "Jupyter Variables", "when": "jupyter.hasNativeNotebookOrInteractiveWindowOpen" } ] diff --git a/package.nls.json b/package.nls.json index e40595650c7..214058395a1 100644 --- a/package.nls.json +++ b/package.nls.json @@ -122,8 +122,8 @@ "jupyter.command.jupyter.showDataViewer.title": "View Value in Data Viewer", "jupyter.command.jupyter.viewOutput.title": "Show Output", "jupyter.command.jupyter.clearSavedJupyterUris.title": "Clear Jupyter Remote Server List", - "jupyter.command.jupyter.openVariableView.title": "Open Variables View", - "jupyter.command.jupyter.openVariableView.shorttitle": "Variables", + "jupyter.command.jupyter.openVariableView.title": "Open Jupyter Variables View", + "jupyter.command.jupyter.openVariableView.shorttitle": "Jupyter Variables", "jupyter.command.jupyter.openOutlineView.title": "Show Table Of Contents (Outline View)", "jupyter.command.jupyter.openOutlineView.shorttitle": "Outline", "jupyter.command.manageAccessToKernels": "Manage Access To Jupyter Kernels", diff --git a/src/standalone/context/activeEditorContext.ts b/src/standalone/context/activeEditorContext.ts index 9059eee5ef5..e905251d144 100644 --- a/src/standalone/context/activeEditorContext.ts +++ b/src/standalone/context/activeEditorContext.ts @@ -2,7 +2,7 @@ // Licensed under the MIT License. import { inject, injectable, optional } from 'inversify'; -import { NotebookEditor, TextEditor, window, workspace } from 'vscode'; +import { NotebookDocument, NotebookEditor, TextEditor, window, workspace } from 'vscode'; import { IKernel, IKernelProvider, isRemoteConnection } from '../../kernels/types'; import { IExtensionSyncActivationService } from '../../platform/activation/types'; import { EditorContexts, PYTHON_LANGUAGE } from '../../platform/common/constants'; @@ -98,16 +98,6 @@ export class ActiveEditorContextService implements IExtensionSyncActivationServi if (window.activeTextEditor?.document.languageId === PYTHON_LANGUAGE) { this.onDidChangeActiveTextEditor(window.activeTextEditor); } - window.onDidChangeNotebookEditorSelection( - this.updateNativeNotebookInteractiveWindowOpenContext, - this, - this.disposables - ); - workspace.onDidOpenNotebookDocument( - this.updateNativeNotebookInteractiveWindowOpenContext, - this, - this.disposables - ); workspace.onDidCloseNotebookDocument( this.updateNativeNotebookInteractiveWindowOpenContext, this, @@ -124,7 +114,6 @@ export class ActiveEditorContextService implements IExtensionSyncActivationServi } private onDidChangeActiveInteractiveWindow(e?: IInteractiveWindow) { this.interactiveContext.set(!!e).catch(noop); - this.updateNativeNotebookInteractiveWindowOpenContext(); this.updateMergedContexts(); this.updateContextOfActiveInteractiveWindowKernel(); } @@ -137,19 +126,20 @@ export class ActiveEditorContextService implements IExtensionSyncActivationServi .catch(noop); this.updateContextOfActiveNotebookKernel(e); this.updateContextOfActiveInteractiveWindowKernel(); - this.updateNativeNotebookInteractiveWindowOpenContext(); this.updateNativeNotebookCellContext(); this.updateMergedContexts(); } - private updateNativeNotebookInteractiveWindowOpenContext() { - this.hasNativeNotebookOrInteractiveWindowOpen - .set( - workspace.notebookDocuments.some( - (nb) => nb.notebookType === JupyterNotebookView || nb.notebookType === InteractiveWindowView - ) - ) - .catch(noop); + + private ownedOpenNotebooks = new Set(); + private updateNativeNotebookInteractiveWindowOpenContext(e: NotebookDocument, jupyterKernelSelected?: boolean) { + if (jupyterKernelSelected) { + this.ownedOpenNotebooks.add(e); + } else { + this.ownedOpenNotebooks.delete(e); + } + this.hasNativeNotebookOrInteractiveWindowOpen.set(this.ownedOpenNotebooks.size > 0).catch(noop); } + private updateContextOfActiveNotebookKernel(activeEditor?: NotebookEditor) { const kernel = activeEditor && activeEditor.notebook.notebookType === JupyterNotebookView @@ -195,6 +185,7 @@ export class ActiveEditorContextService implements IExtensionSyncActivationServi this.interactiveProvider?.getActiveOrAssociatedInteractiveWindow()?.notebookDocument; if (document && isJupyterNotebook(document) && this.controllers.getSelected(document)) { this.isJupyterKernelSelected.set(true).catch(noop); + this.updateNativeNotebookInteractiveWindowOpenContext(document, true); } else { this.isJupyterKernelSelected.set(false).catch(noop); }