Skip to content

Commit 3be2050

Browse files
authored
Command to select a kernel for a Notebook (#9988)
For #9228
1 parent 7c40f2c commit 3be2050

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

news/1 Enhancements/9228.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added a command to allow users to select a kernel for a `Notebook`.

package.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,12 @@
581581
"command": "python.analysis.clearCache",
582582
"title": "%python.command.python.analysis.clearCache.title%",
583583
"category": "Python"
584+
},
585+
{
586+
"command": "python.datascience.switchKernel",
587+
"title": "%DataScience.selectKernel%",
588+
"category": "Python",
589+
"enablement": "python.datascience.isnativeactive"
584590
}
585591
],
586592
"menus": {
@@ -1011,6 +1017,12 @@
10111017
"command": "python.datascience.execSelectionInteractive",
10121018
"category": "Python",
10131019
"when": "editorFocus && editorLangId == python && python.datascience.featureenabled && python.datascience.ownsSelection"
1020+
},
1021+
{
1022+
"command": "python.datascience.switchKernel",
1023+
"title": "%DataScience.selectKernel%",
1024+
"category": "Python",
1025+
"when": "python.datascience.isnativeactive"
10141026
}
10151027
],
10161028
"view/title": [

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {
479479
// time state changes. We use this opportunity to update our
480480
// extension contexts
481481
if (this.commandManager && this.commandManager.executeCommand) {
482-
const interactiveContext = new ContextKey(EditorContexts.HaveNative, this.commandManager);
483-
interactiveContext.set(!this.isDisposed).catch();
482+
const nativeContext = new ContextKey(EditorContexts.HaveNative, this.commandManager);
483+
nativeContext.set(!this.isDisposed).catch();
484484
const interactiveCellsContext = new ContextKey(EditorContexts.HaveNativeCells, this.commandManager);
485485
const redoableContext = new ContextKey(EditorContexts.HaveNativeRedoableCells, this.commandManager);
486486
const hasCellSelectedContext = new ContextKey(EditorContexts.HaveCellSelected, this.commandManager);
@@ -500,8 +500,8 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {
500500
super.onViewStateChanged(args);
501501

502502
// Update our contexts
503-
const interactiveContext = new ContextKey(EditorContexts.HaveNative, this.commandManager);
504-
interactiveContext.set(args.current.visible && args.current.active).catch();
503+
const nativeContext = new ContextKey(EditorContexts.HaveNative, this.commandManager);
504+
nativeContext.set(args.current.visible && args.current.active).catch();
505505
this._onDidChangeViewState.fire();
506506
}
507507

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class NativeEditorProvider implements INotebookEditorProvider, IAsyncDisp
103103
editor = await this.create(file, contents);
104104
this.onOpenedEditor(editor);
105105
} else {
106-
await editor.show();
106+
await this.showEditor(editor);
107107
}
108108
return editor;
109109
}
@@ -112,7 +112,7 @@ export class NativeEditorProvider implements INotebookEditorProvider, IAsyncDisp
112112
// See if this file is open or not already
113113
const editor = this.activeEditors.get(file.fsPath);
114114
if (editor) {
115-
await editor.show();
115+
await this.showEditor(editor);
116116
}
117117
return editor;
118118
}
@@ -161,17 +161,23 @@ export class NativeEditorProvider implements INotebookEditorProvider, IAsyncDisp
161161
this.openNotebookAndCloseEditor(editor.document, true).ignoreErrors();
162162
}
163163

164+
private async showEditor(editor: INotebookEditor) {
165+
await editor.show();
166+
this._onDidChangeActiveNotebookEditor.fire(this.activeEditor);
167+
}
168+
164169
private async create(file: Uri, contents: string): Promise<INotebookEditor> {
165170
const editor = this.serviceContainer.get<INotebookEditor>(INotebookEditor);
166171
await editor.load(contents, file);
167172
this.disposables.push(editor.closed(this.onClosedEditor.bind(this)));
168173
this.disposables.push(editor.executed(this.onExecutedEditor.bind(this)));
169-
await editor.show();
174+
await this.showEditor(editor);
170175
return editor;
171176
}
172177

173178
private onClosedEditor(e: INotebookEditor) {
174179
this.activeEditors.delete(e.file.fsPath);
180+
this._onDidChangeActiveNotebookEditor.fire(this.activeEditor);
175181
}
176182

177183
private onExecutedEditor(e: INotebookEditor) {
@@ -183,6 +189,7 @@ export class NativeEditorProvider implements INotebookEditorProvider, IAsyncDisp
183189
this.disposables.push(e.saved(this.onSavedEditor.bind(this, e.file.fsPath)));
184190
this.openedNotebookCount += 1;
185191
this._onDidOpenNotebookEditor.fire(e);
192+
this._onDidChangeActiveNotebookEditor.fire(this.activeEditor);
186193
this.disposables.push(e.onDidChangeViewState(this.onDidChangeViewState, this));
187194
}
188195
private onDidChangeViewState() {

0 commit comments

Comments
 (0)