forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivation.ts
More file actions
57 lines (51 loc) · 2.63 KB
/
activation.ts
File metadata and controls
57 lines (51 loc) · 2.63 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
// 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 { IPythonExecutionFactory } from '../common/process/types';
import { IDisposableRegistry } from '../common/types';
import { debounceAsync, swallowExceptions } from '../common/utils/decorators';
import { sendTelemetryEvent } from '../telemetry';
import { PythonDaemonModule, Telemetry } from './constants';
import { ActiveEditorContextService } from './context/activeEditorContext';
import { JupyterInterpreterService } from './jupyter/interpreter/jupyterInterpreterService';
import { 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
) {}
public async activate(): Promise<void> {
this.disposables.push(this.notebookEditorProvider.onDidOpenNotebookEditor(this.onDidOpenNotebookEditor, this));
this.disposables.push(this.jupyterInterpreterService.onDidChangeInterpreter(this.onDidChangeInterpreter, this));
// Warm up our selected interpreter for the extension
this.jupyterInterpreterService.setInitialInterpreter().ignoreErrors();
this.contextService.activate().ignoreErrors();
}
private onDidOpenNotebookEditor(_: INotebookEditor) {
this.notebookOpened = true;
this.PreWarmDaemonPool().ignoreErrors();
sendTelemetryEvent(Telemetry.OpenNotebookAll);
}
private onDidChangeInterpreter() {
if (this.notebookOpened) {
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({ daemonModule: PythonDaemonModule, pythonPath: interpreter.path });
}
}