From 19e12ec3b915a1495550b031ec1a9397cbf139da Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Tue, 9 Aug 2022 15:51:03 -0700 Subject: [PATCH] Create factory function --- src/client/apiTypes.ts | 9 ++++----- src/client/pythonEnvironments/base/locator.ts | 7 ++----- .../pythonEnvironments/base/locators/wrappers.ts | 12 ++++++------ 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/client/apiTypes.ts b/src/client/apiTypes.ts index ce718a144c02..f2bdaf39f52a 100644 --- a/src/client/apiTypes.ts +++ b/src/client/apiTypes.ts @@ -245,18 +245,17 @@ export interface IProposedExtensionAPI { registerEnvironmentProvider( environmentProvider: IEnvironmentProvider, metadata: EnvironmentProviderMetadata, - ): Promise; + ): Promise; // TODO: Disposable?? }; } interface IEnvironmentProvider { - locator: ILocatorClass; + // TODO: createEnv + createLocator: ILocatorFactory; getEnvironmentDetails: (env: EnvInfo) => Promise; } -export interface ILocatorClass { - new (root?: string): ILocatorAPI; -} +export type ILocatorFactory = (root?: string) => ILocatorAPI; export interface ILocatorAPI { iterEnvs?(): IPythonEnvsIterator; diff --git a/src/client/pythonEnvironments/base/locator.ts b/src/client/pythonEnvironments/base/locator.ts index 5dd9304fdb62..d757566f9b44 100644 --- a/src/client/pythonEnvironments/base/locator.ts +++ b/src/client/pythonEnvironments/base/locator.ts @@ -14,10 +14,7 @@ import { PythonEnvsWatcher, } from './watcher'; -export interface ILocatorClass { - new (root?: string): ILocatorAPI; -} - +export type ILocatorFactory = (root?: string) => ILocatorAPI; export interface ILocatorAPI { iterEnvs?(): IPythonEnvsIterator; readonly onChanged?: Event; @@ -232,7 +229,7 @@ export interface ILocator { return combineIterators(iterators); } - public addNewLocator(LocatorClass: ILocatorClass, isWorkspace: boolean): void { + public addNewLocator(locatorFactory: ILocatorFactory, isWorkspace: boolean): void { if (isWorkspace) { - this.workspace.addNewLocator(LocatorClass); + this.workspace.addNewLocator(locatorFactory); } if (!isWorkspace) { - this.nonWorkspace = [...this.nonWorkspace, new CustomLocator(new LocatorClass())]; + this.nonWorkspace = [...this.nonWorkspace, new CustomLocator(locatorFactory())]; } } } @@ -145,10 +145,10 @@ export class WorkspaceLocators extends LazyResourceBasedLocator { ); } - public addNewLocator(LocatorClass: ILocatorClass): void { + public addNewLocator(locatorFactory: ILocatorFactory): void { Object.keys(this.roots).forEach((key) => { const root = this.roots[key]; - const newLocator = new LocatorClass(root.fsPath); + const newLocator = locatorFactory(root.fsPath); const convertedLocator: ILocator = new CustomLocator(newLocator); const [locators] = this.locators[key]; locators.addLocator(convertedLocator);