Skip to content

Commit 6bad0ef

Browse files
Initialize/activate the ExtensionLocators when the extension activates. (#13498)
This finishes up work on "interfaces and scaffolding needed for locators". At this point we can plug this "locator manager" into the discovery component API, as well as plug the low-level locators in here.
1 parent b6ee6c6 commit 6bad0ef

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

src/client/extensionInit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { GLOBAL_MEMENTO, IDisposableRegistry, IExtensionContext, IMemento, WORKS
1212
import { ServiceContainer } from './ioc/container';
1313
import { ServiceManager } from './ioc/serviceManager';
1414
import { IServiceContainer, IServiceManager } from './ioc/types';
15-
import { registerForIOC } from './pythonEnvironments/legacyIOC';
15+
import { activate as activatePythonEnvironments } from './pythonEnvironments';
1616

1717
// The code in this module should do nothing more complex than register
1818
// objects to DI and simple init (e.g. no side effects). That implies
@@ -40,6 +40,6 @@ export function initializeComponents(
4040
serviceManager: IServiceManager,
4141
serviceContainer: IServiceContainer
4242
) {
43-
registerForIOC(serviceManager, serviceContainer);
43+
activatePythonEnvironments(serviceManager, serviceContainer);
4444
// We will be pulling code over from activateLegacy().
4545
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
import * as vscode from 'vscode';
5+
import { IServiceContainer, IServiceManager } from '../ioc/types';
6+
import { ILocator } from './base/locator';
7+
import { ExtensionLocators, WorkspaceLocators } from './discovery/locators';
8+
import { registerForIOC } from './legacyIOC';
9+
10+
export function activate(serviceManager: IServiceManager, serviceContainer: IServiceContainer) {
11+
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+
};
58+
}

0 commit comments

Comments
 (0)