Skip to content

Commit b4afa82

Browse files
Initialize and activate the locators when we activate the component.
1 parent 4598443 commit b4afa82

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,58 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
import * as vscode from 'vscode';
45
import { IServiceContainer, IServiceManager } from '../ioc/types';
6+
import { ILocator } from './base/locator';
7+
import { ExtensionLocators, WorkspaceLocators } from './discovery/locators';
58
import { registerForIOC } from './legacyIOC';
69

710
export function activate(serviceManager: IServiceManager, serviceContainer: IServiceContainer) {
811
registerForIOC(serviceManager, serviceContainer);
12+
13+
const [locators, activateLocators] = initLocators();
14+
activateLocators();
15+
// We will pass the locators into the component API.
16+
// tslint:disable-next-line:no-unused-expression
17+
locators;
18+
}
19+
20+
function initLocators(): [ExtensionLocators, () => void] {
21+
// We will add locators in similar order
22+
// to PythonInterpreterLocatorService.getLocators().
23+
const nonWorkspaceLocators: ILocator[] = [
24+
// Add an ILocator object here for each non-workspace locator.
25+
];
26+
27+
const workspaceLocators = new WorkspaceLocators([
28+
// Add an ILocator factory func here for each kind of workspace-rooted locator.
29+
]);
30+
31+
return [
32+
new ExtensionLocators(nonWorkspaceLocators, workspaceLocators),
33+
// combined activation func:
34+
() => {
35+
// Any non-workspace locator activation goes here.
36+
workspaceLocators.activate(getWorkspaceFolders());
37+
}
38+
];
39+
}
40+
41+
function getWorkspaceFolders() {
42+
const rootAdded = new vscode.EventEmitter<vscode.Uri>();
43+
const rootRemoved = new vscode.EventEmitter<vscode.Uri>();
44+
vscode.workspace.onDidChangeWorkspaceFolders((event) => {
45+
for (const root of event.removed) {
46+
rootRemoved.fire(root.uri);
47+
}
48+
for (const root of event.added) {
49+
rootAdded.fire(root.uri);
50+
}
51+
});
52+
const folders = vscode.workspace.workspaceFolders;
53+
return {
54+
roots: folders ? folders.map((f) => f.uri) : [],
55+
onAdded: rootAdded.event,
56+
onRemoved: rootRemoved.event
57+
};
958
}

0 commit comments

Comments
 (0)