forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivation.ts
More file actions
69 lines (63 loc) · 3.4 KB
/
activation.ts
File metadata and controls
69 lines (63 loc) · 3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';
import { IExtensionSingleActivationService } from '../activation/types';
import '../common/extensions';
import { IPythonDaemonExecutionService, IPythonExecutionFactory } from '../common/process/types';
import { IDisposableRegistry } from '../common/types';
import { debounceAsync, swallowExceptions } from '../common/utils/decorators';
import { sendTelemetryEvent, setSharedProperty } from '../telemetry';
import { JupyterDaemonModule, Telemetry } from './constants';
import { ActiveEditorContextService } from './context/activeEditorContext';
import { JupyterInterpreterService } from './jupyter/interpreter/jupyterInterpreterService';
import { KernelDaemonPreWarmer } from './kernel-launcher/kernelDaemonPreWarmer';
import { INotebookAndInteractiveWindowUsageTracker, INotebookEditor, INotebookEditorProvider } from './types';
@injectable()
export class Activation implements IExtensionSingleActivationService {
private notebookOpened = false;
constructor(
@inject(INotebookEditorProvider) private readonly notebookEditorProvider: INotebookEditorProvider,
@inject(JupyterInterpreterService) private readonly jupyterInterpreterService: JupyterInterpreterService,
@inject(IPythonExecutionFactory) private readonly factory: IPythonExecutionFactory,
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry,
@inject(ActiveEditorContextService) private readonly contextService: ActiveEditorContextService,
@inject(KernelDaemonPreWarmer) private readonly daemonPoolPrewarmer: KernelDaemonPreWarmer,
@inject(INotebookAndInteractiveWindowUsageTracker)
private readonly tracker: INotebookAndInteractiveWindowUsageTracker
) {}
public async activate(): Promise<void> {
this.disposables.push(this.notebookEditorProvider.onDidOpenNotebookEditor(this.onDidOpenNotebookEditor, this));
this.disposables.push(this.jupyterInterpreterService.onDidChangeInterpreter(this.onDidChangeInterpreter, this));
this.contextService.activate().ignoreErrors();
this.daemonPoolPrewarmer.activate(undefined).ignoreErrors();
this.tracker.startTracking();
}
private onDidOpenNotebookEditor(e: INotebookEditor) {
this.notebookOpened = true;
this.PreWarmDaemonPool().ignoreErrors();
setSharedProperty('ds_notebookeditor', e.type);
sendTelemetryEvent(Telemetry.OpenNotebookAll);
// Warm up our selected interpreter for the extension
this.jupyterInterpreterService.setInitialInterpreter().ignoreErrors();
}
private onDidChangeInterpreter() {
if (this.notebookOpened) {
// Warm up our selected interpreter for the extension
this.jupyterInterpreterService.setInitialInterpreter().ignoreErrors();
this.PreWarmDaemonPool().ignoreErrors();
}
}
@debounceAsync(500)
@swallowExceptions('Failed to pre-warm daemon pool')
private async PreWarmDaemonPool() {
const interpreter = await this.jupyterInterpreterService.getSelectedInterpreter();
if (!interpreter) {
return;
}
await this.factory.createDaemon<IPythonDaemonExecutionService>({
daemonModule: JupyterDaemonModule,
pythonPath: interpreter.path
});
}
}