Skip to content

Initialize/activate the ExtensionLocators when the extension activates. #13498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/client/extensionInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { GLOBAL_MEMENTO, IDisposableRegistry, IExtensionContext, IMemento, WORKS
import { ServiceContainer } from './ioc/container';
import { ServiceManager } from './ioc/serviceManager';
import { IServiceContainer, IServiceManager } from './ioc/types';
import { registerForIOC } from './pythonEnvironments/legacyIOC';
import { activate as activatePythonEnvironments } from './pythonEnvironments';

// 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
Expand Down Expand Up @@ -40,6 +40,6 @@ export function initializeComponents(
serviceManager: IServiceManager,
serviceContainer: IServiceContainer
) {
registerForIOC(serviceManager, serviceContainer);
activatePythonEnvironments(serviceManager, serviceContainer);
// We will be pulling code over from activateLegacy().
}
58 changes: 58 additions & 0 deletions src/client/pythonEnvironments/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
};
}