forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextensionInit.ts
More file actions
99 lines (85 loc) · 3.99 KB
/
extensionInit.ts
File metadata and controls
99 lines (85 loc) · 3.99 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { Container } from 'inversify';
import { Disposable, Memento, OutputChannel, window } from 'vscode';
import { STANDARD_OUTPUT_CHANNEL } from './common/constants';
import { registerTypes as platformRegisterTypes } from './common/platform/serviceRegistry';
import { registerTypes as processRegisterTypes } from './common/process/serviceRegistry';
import { registerTypes as commonRegisterTypes } from './common/serviceRegistry';
import {
GLOBAL_MEMENTO,
IDisposableRegistry,
IExtensionContext,
IMemento,
IOutputChannel,
WORKSPACE_MEMENTO,
} from './common/types';
import { registerTypes as variableRegisterTypes } from './common/variables/serviceRegistry';
import { OutputChannelNames } from './common/utils/localize';
import { ExtensionState } from './components';
import { ServiceContainer } from './ioc/container';
import { ServiceManager } from './ioc/serviceManager';
import { IServiceContainer, IServiceManager } from './ioc/types';
import { addOutputChannelLogging } from './logging';
import * as pythonEnvironments from './pythonEnvironments';
import { PythonEnvironments } from './pythonEnvironments/api';
import { TEST_OUTPUT_CHANNEL } from './testing/constants';
// The code in this module should do nothing more complex than register
// objects to DI and simple init (e.g. no side effects). That implies
// that constructors are likewise simple and do no work. It also means
// that it is inherently synchronous.
export function initializeGlobals(
// This is stored in ExtensionState.
context: IExtensionContext,
): ExtensionState {
const cont = new Container({ skipBaseClassChecks: true });
const serviceManager = new ServiceManager(cont);
const serviceContainer = new ServiceContainer(cont);
const disposables: IDisposableRegistry = context.subscriptions;
serviceManager.addSingletonInstance<IServiceContainer>(IServiceContainer, serviceContainer);
serviceManager.addSingletonInstance<IServiceManager>(IServiceManager, serviceManager);
serviceManager.addSingletonInstance<Disposable[]>(IDisposableRegistry, disposables);
serviceManager.addSingletonInstance<Memento>(IMemento, context.globalState, GLOBAL_MEMENTO);
serviceManager.addSingletonInstance<Memento>(IMemento, context.workspaceState, WORKSPACE_MEMENTO);
serviceManager.addSingletonInstance<IExtensionContext>(IExtensionContext, context);
const standardOutputChannel = window.createOutputChannel(OutputChannelNames.python());
addOutputChannelLogging(standardOutputChannel);
const unitTestOutChannel = window.createOutputChannel(OutputChannelNames.pythonTest());
serviceManager.addSingletonInstance<OutputChannel>(IOutputChannel, standardOutputChannel, STANDARD_OUTPUT_CHANNEL);
serviceManager.addSingletonInstance<OutputChannel>(IOutputChannel, unitTestOutChannel, TEST_OUTPUT_CHANNEL);
return {
context,
disposables,
legacyIOC: { serviceManager, serviceContainer },
};
}
/**
* Registers standard utils like experiment and platform code which are fundamental to the extension.
*/
export function initializeStandard(ext: ExtensionState): void {
const { serviceManager } = ext.legacyIOC;
// Core registrations (non-feature specific).
commonRegisterTypes(serviceManager);
variableRegisterTypes(serviceManager);
platformRegisterTypes(serviceManager);
processRegisterTypes(serviceManager);
// We will be pulling other code over from activateLegacy().
}
/**
* The set of public APIs from initialized components.
*/
export type Components = {
pythonEnvs: PythonEnvironments;
};
/**
* Initialize all components in the extension.
*/
export async function initializeComponents(ext: ExtensionState): Promise<Components> {
const pythonEnvs = await pythonEnvironments.initialize(ext);
// Other component initializers go here.
// We will be factoring them out of activateLegacy().
return {
pythonEnvs,
};
}