forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextensionActivation.ts
More file actions
228 lines (187 loc) · 11.9 KB
/
extensionActivation.ts
File metadata and controls
228 lines (187 loc) · 11.9 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
// tslint:disable:max-func-body-length
import { CodeActionKind, debug, DebugConfigurationProvider, languages, OutputChannel, window } from 'vscode';
import { registerTypes as activationRegisterTypes } from './activation/serviceRegistry';
import { IExtensionActivationManager, ILanguageServerExtension } from './activation/types';
import { registerTypes as appRegisterTypes } from './application/serviceRegistry';
import { IApplicationDiagnostics } from './application/types';
import { DebugService } from './common/application/debugService';
import { IApplicationEnvironment, ICommandManager, IWorkspaceService } from './common/application/types';
import { Commands, PYTHON, PYTHON_LANGUAGE, STANDARD_OUTPUT_CHANNEL, UseProposedApi } from './common/constants';
import { registerTypes as installerRegisterTypes } from './common/installer/serviceRegistry';
import { traceError } from './common/logger';
import { registerTypes as platformRegisterTypes } from './common/platform/serviceRegistry';
import { IFileSystem } from './common/platform/types';
import { registerTypes as processRegisterTypes } from './common/process/serviceRegistry';
import { registerTypes as commonRegisterTypes } from './common/serviceRegistry';
import {
IConfigurationService,
IDisposableRegistry,
IExperimentsManager,
IExtensionContext,
IFeatureDeprecationManager,
IOutputChannel
} from './common/types';
import { OutputChannelNames } from './common/utils/localize';
import { noop } from './common/utils/misc';
import { registerTypes as variableRegisterTypes } from './common/variables/serviceRegistry';
import { JUPYTER_OUTPUT_CHANNEL } from './datascience/constants';
import { registerTypes as dataScienceRegisterTypes } from './datascience/serviceRegistry';
import { IDataScience } from './datascience/types';
import { DebuggerTypeName } from './debugger/constants';
import { DebugSessionEventDispatcher } from './debugger/extension/hooks/eventHandlerDispatcher';
import { IDebugSessionEventHandlers } from './debugger/extension/hooks/types';
import { registerTypes as debugConfigurationRegisterTypes } from './debugger/extension/serviceRegistry';
import { IDebugConfigurationService, IDebuggerBanner } from './debugger/extension/types';
import { registerTypes as formattersRegisterTypes } from './formatters/serviceRegistry';
import {
IInterpreterLocatorProgressHandler,
IInterpreterLocatorProgressService,
IInterpreterService
} from './interpreter/contracts';
import { registerTypes as interpretersRegisterTypes } from './interpreter/serviceRegistry';
import { IServiceContainer, IServiceManager } from './ioc/types';
import { getLanguageConfiguration } from './language/languageConfiguration';
import { LinterCommands } from './linters/linterCommands';
import { registerTypes as lintersRegisterTypes } from './linters/serviceRegistry';
import { addOutputChannelLogging, setLoggingLevel } from './logging';
import { PythonCodeActionProvider } from './providers/codeActionProvider/pythonCodeActionProvider';
import { PythonFormattingEditProvider } from './providers/formatProvider';
import { ReplProvider } from './providers/replProvider';
import { registerTypes as providersRegisterTypes } from './providers/serviceRegistry';
import { activateSimplePythonRefactorProvider } from './providers/simpleRefactorProvider';
import { TerminalProvider } from './providers/terminalProvider';
import { ISortImportsEditingProvider } from './providers/types';
import { setExtensionInstallTelemetryProperties } from './telemetry/extensionInstallTelemetry';
import { registerTypes as commonRegisterTerminalTypes } from './terminals/serviceRegistry';
import { ICodeExecutionManager, ITerminalAutoActivation } from './terminals/types';
import { TEST_OUTPUT_CHANNEL } from './testing/common/constants';
import { ITestContextService } from './testing/common/types';
import { ITestCodeNavigatorCommandHandler, ITestExplorerCommandHandler } from './testing/navigation/types';
import { registerTypes as unitTestsRegisterTypes } from './testing/serviceRegistry';
export async function activateComponents(
context: IExtensionContext,
serviceManager: IServiceManager,
serviceContainer: IServiceContainer
) {
// We will be pulling code over from activateLegacy().
return activateLegacy(context, serviceManager, serviceContainer);
}
/////////////////////////////
// old activation code
// tslint:disable-next-line:no-suspicious-comment
// TODO: Gradually move simple initialization
// and DI registration currently in this function over
// to initializeComponents(). Likewise with complex
// init and activation: move them to activateComponents().
// See https://github.com/microsoft/vscode-python/issues/10454.
async function activateLegacy(
context: IExtensionContext,
serviceManager: IServiceManager,
serviceContainer: IServiceContainer
) {
// register "services"
const standardOutputChannel = window.createOutputChannel(OutputChannelNames.python());
addOutputChannelLogging(standardOutputChannel);
const unitTestOutChannel = window.createOutputChannel(OutputChannelNames.pythonTest());
const jupyterOutputChannel = window.createOutputChannel(OutputChannelNames.jupyter());
serviceManager.addSingletonInstance<OutputChannel>(IOutputChannel, standardOutputChannel, STANDARD_OUTPUT_CHANNEL);
serviceManager.addSingletonInstance<OutputChannel>(IOutputChannel, unitTestOutChannel, TEST_OUTPUT_CHANNEL);
serviceManager.addSingletonInstance<OutputChannel>(IOutputChannel, jupyterOutputChannel, JUPYTER_OUTPUT_CHANNEL);
// Core registrations (non-feature specific).
commonRegisterTypes(serviceManager);
platformRegisterTypes(serviceManager);
processRegisterTypes(serviceManager);
// We need to setup this property before any telemetry is sent
const fs = serviceManager.get<IFileSystem>(IFileSystem);
await setExtensionInstallTelemetryProperties(fs);
const applicationEnv = serviceManager.get<IApplicationEnvironment>(IApplicationEnvironment);
const enableProposedApi = applicationEnv.packageJson.enableProposedApi;
serviceManager.addSingletonInstance<boolean>(UseProposedApi, enableProposedApi);
// Feature specific registrations.
variableRegisterTypes(serviceManager);
unitTestsRegisterTypes(serviceManager);
lintersRegisterTypes(serviceManager);
interpretersRegisterTypes(serviceManager);
formattersRegisterTypes(serviceManager);
installerRegisterTypes(serviceManager);
commonRegisterTerminalTypes(serviceManager);
debugConfigurationRegisterTypes(serviceManager);
const configuration = serviceManager.get<IConfigurationService>(IConfigurationService);
// We should start logging using the log level as soon as possible, so set it as soon as we can access the level.
// `IConfigurationService` may depend any of the registered types, so doing it after all registrations are finished.
// XXX Move this *after* abExperiments is activated?
setLoggingLevel(configuration.getSettings().logging.level);
const abExperiments = serviceContainer.get<IExperimentsManager>(IExperimentsManager);
await abExperiments.activate();
// Register datascience types after experiments have loaded.
// To ensure we can register types based on experiments.
dataScienceRegisterTypes(serviceManager);
const languageServerType = configuration.getSettings().languageServer;
// Language feature registrations.
appRegisterTypes(serviceManager, languageServerType);
providersRegisterTypes(serviceManager);
activationRegisterTypes(serviceManager, languageServerType);
// "initialize" "services"
const interpreterManager = serviceContainer.get<IInterpreterService>(IInterpreterService);
interpreterManager.initialize();
const handlers = serviceManager.getAll<IDebugSessionEventHandlers>(IDebugSessionEventHandlers);
const disposables = serviceManager.get<IDisposableRegistry>(IDisposableRegistry);
const dispatcher = new DebugSessionEventDispatcher(handlers, DebugService.instance, disposables);
dispatcher.registerEventHandlers();
const cmdManager = serviceContainer.get<ICommandManager>(ICommandManager);
const outputChannel = serviceManager.get<OutputChannel>(IOutputChannel, STANDARD_OUTPUT_CHANNEL);
disposables.push(cmdManager.registerCommand(Commands.ViewOutput, () => outputChannel.show()));
cmdManager.executeCommand('setContext', 'python.vscode.channel', applicationEnv.channel).then(noop, noop);
// Display progress of interpreter refreshes only after extension has activated.
serviceContainer.get<IInterpreterLocatorProgressHandler>(IInterpreterLocatorProgressHandler).register();
serviceContainer.get<IInterpreterLocatorProgressService>(IInterpreterLocatorProgressService).register();
serviceContainer.get<IApplicationDiagnostics>(IApplicationDiagnostics).register();
serviceContainer.get<ITestCodeNavigatorCommandHandler>(ITestCodeNavigatorCommandHandler).register();
serviceContainer.get<ITestExplorerCommandHandler>(ITestExplorerCommandHandler).register();
serviceContainer.get<ILanguageServerExtension>(ILanguageServerExtension).register();
serviceContainer.get<ITestContextService>(ITestContextService).register();
// "activate" everything else
const manager = serviceContainer.get<IExtensionActivationManager>(IExtensionActivationManager);
context.subscriptions.push(manager);
const activationPromise = manager.activate();
serviceManager.get<ITerminalAutoActivation>(ITerminalAutoActivation).register();
const pythonSettings = configuration.getSettings();
activateSimplePythonRefactorProvider(context, standardOutputChannel, serviceContainer);
const sortImports = serviceContainer.get<ISortImportsEditingProvider>(ISortImportsEditingProvider);
sortImports.registerCommands();
serviceManager.get<ICodeExecutionManager>(ICodeExecutionManager).registerCommands();
const workspaceService = serviceContainer.get<IWorkspaceService>(IWorkspaceService);
interpreterManager
.refresh(workspaceService.hasWorkspaceFolders ? workspaceService.workspaceFolders![0].uri : undefined)
.catch((ex) => traceError('Python Extension: interpreterManager.refresh', ex));
// Activate data science features
const dataScience = serviceManager.get<IDataScience>(IDataScience);
dataScience.activate().ignoreErrors();
context.subscriptions.push(new LinterCommands(serviceManager));
languages.setLanguageConfiguration(PYTHON_LANGUAGE, getLanguageConfiguration());
if (pythonSettings && pythonSettings.formatting && pythonSettings.formatting.provider !== 'internalConsole') {
const formatProvider = new PythonFormattingEditProvider(context, serviceContainer);
context.subscriptions.push(languages.registerDocumentFormattingEditProvider(PYTHON, formatProvider));
context.subscriptions.push(languages.registerDocumentRangeFormattingEditProvider(PYTHON, formatProvider));
}
const deprecationMgr = serviceContainer.get<IFeatureDeprecationManager>(IFeatureDeprecationManager);
deprecationMgr.initialize();
context.subscriptions.push(deprecationMgr);
context.subscriptions.push(new ReplProvider(serviceContainer));
const terminalProvider = new TerminalProvider(serviceContainer);
terminalProvider.initialize(window.activeTerminal).ignoreErrors();
context.subscriptions.push(terminalProvider);
context.subscriptions.push(
languages.registerCodeActionsProvider(PYTHON, new PythonCodeActionProvider(), {
providedCodeActionKinds: [CodeActionKind.SourceOrganizeImports]
})
);
serviceContainer.getAll<DebugConfigurationProvider>(IDebugConfigurationService).forEach((debugConfigProvider) => {
context.subscriptions.push(debug.registerDebugConfigurationProvider(DebuggerTypeName, debugConfigProvider));
});
serviceContainer.get<IDebuggerBanner>(IDebuggerBanner).initialize();
return { activationPromise };
}