Skip to content

Commit 677c761

Browse files
authored
Add run notebook in dedicated extension host command (#9492)
1 parent 1455d0b commit 677c761

File tree

5 files changed

+76
-1
lines changed

5 files changed

+76
-1
lines changed

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"onCommand:jupyter.selectNativeJupyterUriFromToolBar",
6969
"onCommand:jupyter.clearSavedJupyterUris",
7070
"onCommand:jupyter.filterKernels",
71+
"onCommand:jupyter.runInDedicatedExtensionHost",
7172
"onWalkthrough:jupyterWelcome",
7273
"onNotebook:jupyter-notebook",
7374
"onNotebook:interactive"
@@ -812,6 +813,11 @@
812813
"title": "%DataScience.interactiveCopyCell%",
813814
"icon": "$(copy)",
814815
"category": "Jupyter"
816+
},
817+
{
818+
"command": "jupyter.runInDedicatedExtensionHost",
819+
"title": "%DataScience.runInDedicatedExtensionHost%",
820+
"category": "Jupyter"
815821
}
816822
],
817823
"menus": {

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@
171171
"DataScience.expandVariableExplorerTooltip": "Show variables active in jupyter kernel",
172172
"DataScience.close": "Close",
173173
"DataScience.interactiveCopyCell": "Copy Cell",
174+
"DataScience.runInDedicatedExtensionHost": "Run in Dedicated Extension Host",
174175
"DataScience.variableLoadingValue": "Loading...",
175176
"DataScience.importDialogTitle": "Import Jupyter Notebook",
176177
"DataScience.importDialogFilter": "Jupyter Notebooks",
@@ -572,4 +573,4 @@
572573
"Installer.couldNotInstallLibrary": "Could not install {0}. If pip is not available, please use the package manager of your choice to manually install this library into your Python environment.",
573574
"Installer.dataScienceInstallPrompt": "Data Science library {0} is not installed. Install?",
574575
"Products.installingModule": "Installing {0}"
575-
}
576+
}

src/platform/common/application/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export interface ICommandNameArgumentTypeMapping extends ICommandNameWithoutArgu
8686
['extension.open']: [string];
8787
['setContext']: [string, boolean] | ['jupyter.vscode.channel', Channel];
8888
['jupyter.reloadVSCode']: [string];
89+
['jupyter.runInDedicatedExtensionHost']: [string];
8990
['revealLine']: [{ lineNumber: number; at: 'top' | 'center' | 'bottom' }];
9091
['python._loadLanguageServerExtension']: {}[];
9192
['python.SelectAndInsertDebugConfiguration']: [TextDocument, Position, CancellationToken];
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
'use strict';
5+
6+
import { inject, injectable } from 'inversify';
7+
import { ConfigurationTarget, extensions } from 'vscode';
8+
import { IExtensionSingleActivationService } from '../../../activation/types';
9+
import { PythonExtension, PylanceExtension } from '../../constants';
10+
import { noop } from '../../utils/misc';
11+
import { ICommandManager, IWorkspaceService } from '../types';
12+
13+
/**
14+
* Prompts user to reload VS Code with a custom message, and reloads if necessary.
15+
*/
16+
@injectable()
17+
export class RunInDedicatedExtensionHostCommandHandler implements IExtensionSingleActivationService {
18+
constructor(
19+
@inject(ICommandManager) private readonly commandManager: ICommandManager,
20+
@inject(IWorkspaceService) private readonly workspaceService: IWorkspaceService
21+
) {}
22+
public async activate(): Promise<void> {
23+
this.commandManager.registerCommand('jupyter.runInDedicatedExtensionHost', this.updateAffinity, this);
24+
}
25+
private async updateAffinity() {
26+
const affinity = this.workspaceService.getConfiguration('extensions').get('experimental.affinity') as
27+
| { [key: string]: number }
28+
| undefined;
29+
let maxAffinity = 0;
30+
if (affinity) {
31+
Object.values(affinity).forEach((value) => {
32+
maxAffinity = Math.max(maxAffinity, value);
33+
});
34+
}
35+
36+
const targetAffinity = maxAffinity + 1;
37+
38+
let update: { [key: string]: number } = {
39+
'ms-toolsai.jupyter': targetAffinity,
40+
'ms-toolsai.jupyter-renderers': targetAffinity
41+
};
42+
43+
if (extensions.getExtension(PythonExtension)) {
44+
update[PythonExtension] = targetAffinity;
45+
}
46+
47+
if (extensions.getExtension(PylanceExtension)) {
48+
update[PylanceExtension] = targetAffinity;
49+
}
50+
51+
await this.workspaceService.getConfiguration('extensions').update(
52+
'experimental.affinity',
53+
{
54+
...(affinity ?? {}),
55+
...update
56+
},
57+
ConfigurationTarget.Global
58+
);
59+
60+
this.commandManager.executeCommand('workbench.action.reloadWindow').then(noop, noop);
61+
}
62+
}

src/platform/common/serviceRegistry.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ActiveResourceService } from './application/activeResource';
1010
import { ApplicationEnvironment } from './application/applicationEnvironment';
1111
import { ClipboardService } from './application/clipboard';
1212
import { ReloadVSCodeCommandHandler } from './application/commands/reloadCommand';
13+
import { RunInDedicatedExtensionHostCommandHandler } from './application/commands/runInDedicatedExtensionHost';
1314
import { DebugService } from './application/debugService';
1415
import { DocumentManager } from './application/documentManager';
1516
import { EncryptedStorage } from './application/encryptedStorage';
@@ -91,6 +92,10 @@ export function registerTypes(serviceManager: IServiceManager) {
9192
IExtensionSingleActivationService,
9293
ReloadVSCodeCommandHandler
9394
);
95+
serviceManager.addSingleton<IExtensionSingleActivationService>(
96+
IExtensionSingleActivationService,
97+
RunInDedicatedExtensionHostCommandHandler
98+
);
9499
serviceManager.addSingleton<IExtensionSingleActivationService>(
95100
IExtensionSingleActivationService,
96101
AmlComputeContext

0 commit comments

Comments
 (0)