Skip to content

Commit

Permalink
Create factory function
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj committed Aug 9, 2022
1 parent 645873a commit 19e12ec
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
9 changes: 4 additions & 5 deletions src/client/apiTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,17 @@ export interface IProposedExtensionAPI {
registerEnvironmentProvider(
environmentProvider: IEnvironmentProvider,
metadata: EnvironmentProviderMetadata,
): Promise<void>;
): Promise<void>; // TODO: Disposable??
};
}

interface IEnvironmentProvider {
locator: ILocatorClass;
// TODO: createEnv
createLocator: ILocatorFactory;
getEnvironmentDetails: (env: EnvInfo) => Promise<EnvironmentDetails | undefined>;
}

export interface ILocatorClass {
new (root?: string): ILocatorAPI;
}
export type ILocatorFactory = (root?: string) => ILocatorAPI;

export interface ILocatorAPI {
iterEnvs?(): IPythonEnvsIterator<EnvInfo>;
Expand Down
7 changes: 2 additions & 5 deletions src/client/pythonEnvironments/base/locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<EnvInfo>;
readonly onChanged?: Event<LocatorEnvsChangedEvent>;
Expand Down Expand Up @@ -232,7 +229,7 @@ export interface ILocator<I = PythonEnvInfo, E extends BasicPythonEnvsChangedEve
}

export interface IEnvProvider {
addNewLocator?(LocatorClass: ILocatorClass, isWorkspace: boolean): void;
addNewLocator?(locatorFactory: ILocatorFactory, isWorkspace: boolean): void;
}

interface IResolver {
Expand Down
12 changes: 6 additions & 6 deletions src/client/pythonEnvironments/base/locators/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

// eslint-disable-next-line max-classes-per-file
import { Uri } from 'vscode';
import { ILocatorClass } from '../../../apiTypes';
import { ILocatorFactory } from '../../../apiTypes';
import { IDisposable } from '../../../common/types';
import { iterEmpty } from '../../../common/utils/async';
import { getURIFilter } from '../../../common/utils/misc';
Expand Down Expand Up @@ -37,12 +37,12 @@ export class ExtensionLocators extends Locators<BasicEnvInfo> {
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())];
}
}
}
Expand Down Expand Up @@ -145,10 +145,10 @@ export class WorkspaceLocators extends LazyResourceBasedLocator<BasicEnvInfo> {
);
}

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<BasicEnvInfo> = new CustomLocator(newLocator);
const [locators] = this.locators[key];
locators.addLocator(convertedLocator);
Expand Down

0 comments on commit 19e12ec

Please sign in to comment.