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
52 lines (46 loc) · 2.23 KB
/
activation.ts
File metadata and controls
52 lines (46 loc) · 2.23 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
// 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 { IInterpreterService } from '../interpreter/contracts';
import { sendTelemetryEvent } from '../telemetry';
import { PythonDaemonModule, Telemetry } from './constants';
import { INotebookEditor, INotebookEditorProvider } from './types';
@injectable()
export class Activation implements IExtensionSingleActivationService {
private notebookOpened = false;
constructor(
@inject(INotebookEditorProvider) private readonly notebookProvider: INotebookEditorProvider,
@inject(IInterpreterService) private readonly interpreterService: IInterpreterService,
@inject(IPythonExecutionFactory) private readonly factory: IPythonExecutionFactory,
@inject(IDisposableRegistry) private readonly disposables: IDisposableRegistry
) { }
public async activate(): Promise<void> {
this.disposables.push(this.notebookProvider.onDidOpenNotebookEditor(this.onDidOpenNotebookEditor, this));
this.disposables.push(this.interpreterService.onDidChangeInterpreter(this.onDidChangeInterpreter, this));
}
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 create daemon when notebook opened')
private async PreWarmDaemonPool() {
const activeInterpreter = await this.interpreterService.getActiveInterpreter(undefined);
if (!activeInterpreter) {
return;
}
await this.factory.createDaemon({ daemonModule: PythonDaemonModule, pythonPath: activeInterpreter.path });
}
}