Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only set notebook open context key if it uses a jupyter kernel #16226

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2020,7 +2020,7 @@
{
"type": "webview",
"id": "jupyterViewVariables",
"name": "Variables",
"name": "Jupyter Variables",
"when": "jupyter.hasNativeNotebookOrInteractiveWindowOpen"
}
]
Expand Down
4 changes: 2 additions & 2 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
33 changes: 12 additions & 21 deletions src/standalone/context/activeEditorContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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();
}
Expand All @@ -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<NotebookDocument>();
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
Expand Down Expand Up @@ -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);
}
Expand Down
Loading