Skip to content

Commit 654aa72

Browse files
authored
Show progress when nb extensions are activating. (microsoft#167003)
1 parent 067d6cc commit 654aa72

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
7+
import { Disposable, DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
8+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
9+
import { Registry } from 'vs/platform/registry/common/platform';
10+
import { Extensions as WorkbenchExtensions, IWorkbenchContribution, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
11+
import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
12+
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
13+
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
14+
15+
class NotebookKernelDetection extends Disposable implements IWorkbenchContribution {
16+
private _detectionMap = new Map<string, IDisposable>();
17+
private _localDisposableStore = new DisposableStore();
18+
constructor(
19+
@INotebookKernelService private readonly _notebookKernelService: INotebookKernelService,
20+
@IExtensionService private readonly _extensionService: IExtensionService,
21+
@IConfigurationService private readonly _configurationService: IConfigurationService,
22+
) {
23+
super();
24+
25+
this._registerListeners();
26+
this._register(this._configurationService.onDidChangeConfiguration(e => {
27+
if (e.affectedKeys.includes('notebook.kernelPicker.type')) {
28+
this._registerListeners();
29+
}
30+
}));
31+
}
32+
33+
private _registerListeners() {
34+
this._localDisposableStore.clear();
35+
36+
const kernelPickerType = this._configurationService.getValue<'all' | 'mru'>('notebook.kernelPicker.type');
37+
38+
if (kernelPickerType === 'mru') {
39+
this._localDisposableStore.add(this._extensionService.onWillActivateByEvent(e => {
40+
if (e.event.startsWith('onNotebook:')) {
41+
if (this._extensionService.activationEventIsDone(e.event)) {
42+
return;
43+
}
44+
45+
// parse the event to get the notebook type
46+
const notebookType = e.event.substring('onNotebook:'.length);
47+
48+
let shouldStartDetection = false;
49+
50+
const extensionStatus = this._extensionService.getExtensionsStatus();
51+
this._extensionService.extensions.forEach(extension => {
52+
if (extensionStatus[extension.identifier.value].activationTimes) {
53+
// already activated
54+
return;
55+
}
56+
if (extension.activationEvents?.includes(e.event)) {
57+
shouldStartDetection = true;
58+
}
59+
});
60+
61+
if (shouldStartDetection) {
62+
const task = this._notebookKernelService.registerNotebookKernelDetectionTask({
63+
notebookType: notebookType
64+
});
65+
66+
this._detectionMap.set(notebookType, task);
67+
}
68+
}
69+
}));
70+
71+
this._register(this._extensionService.onDidChangeExtensionsStatus(() => {
72+
for (const [notebookType, task] of this._detectionMap) {
73+
if (this._extensionService.activationEventIsDone(`onNotebook:${notebookType}`)) {
74+
task.dispose();
75+
}
76+
}
77+
}));
78+
}
79+
}
80+
}
81+
82+
Registry.as<IWorkbenchContributionsRegistry>(WorkbenchExtensions.Workbench).registerWorkbenchContribution(NotebookKernelDetection, LifecyclePhase.Restored);

src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import 'vs/workbench/contrib/notebook/browser/contrib/viewportCustomMarkdown/vie
8888
import 'vs/workbench/contrib/notebook/browser/contrib/troubleshoot/layout';
8989
import 'vs/workbench/contrib/notebook/browser/contrib/breakpoints/notebookBreakpoints';
9090
import 'vs/workbench/contrib/notebook/browser/contrib/execute/executionEditorProgress';
91+
import 'vs/workbench/contrib/notebook/browser/contrib/kernelDetection/notebookKernelDetection';
9192

9293
// Diff Editor Contribution
9394
import 'vs/workbench/contrib/notebook/browser/diff/notebookDiffActions';

0 commit comments

Comments
 (0)