forked from microsoft/vscode-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
58 lines (51 loc) · 2.01 KB
/
index.ts
File metadata and controls
58 lines (51 loc) · 2.01 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as vscode from 'vscode';
import { IServiceContainer, IServiceManager } from '../ioc/types';
import { ILocator } from './base/locator';
import { ExtensionLocators, WorkspaceLocators } from './discovery/locators';
import { registerForIOC } from './legacyIOC';
export function activate(serviceManager: IServiceManager, serviceContainer: IServiceContainer) {
registerForIOC(serviceManager, serviceContainer);
const [locators, activateLocators] = initLocators();
activateLocators();
// We will pass the locators into the component API.
// tslint:disable-next-line:no-unused-expression
locators;
}
function initLocators(): [ExtensionLocators, () => void] {
// We will add locators in similar order
// to PythonInterpreterLocatorService.getLocators().
const nonWorkspaceLocators: ILocator[] = [
// Add an ILocator object here for each non-workspace locator.
];
const workspaceLocators = new WorkspaceLocators([
// Add an ILocator factory func here for each kind of workspace-rooted locator.
]);
return [
new ExtensionLocators(nonWorkspaceLocators, workspaceLocators),
// combined activation func:
() => {
// Any non-workspace locator activation goes here.
workspaceLocators.activate(getWorkspaceFolders());
}
];
}
function getWorkspaceFolders() {
const rootAdded = new vscode.EventEmitter<vscode.Uri>();
const rootRemoved = new vscode.EventEmitter<vscode.Uri>();
vscode.workspace.onDidChangeWorkspaceFolders((event) => {
for (const root of event.removed) {
rootRemoved.fire(root.uri);
}
for (const root of event.added) {
rootAdded.fire(root.uri);
}
});
const folders = vscode.workspace.workspaceFolders;
return {
roots: folders ? folders.map((f) => f.uri) : [],
onAdded: rootAdded.event,
onRemoved: rootRemoved.event
};
}