Skip to content

Commit

Permalink
Change IEnvironmentProvider interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj committed Aug 18, 2022
1 parent df3d795 commit f88636a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
21 changes: 11 additions & 10 deletions src/client/pythonEnvironments/base/locator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,22 @@ interface ILocatorFactoryAPI {

export type ProposedDetailsAPI = (env: BaseEnvInfo) => Promise<EnvironmentDetailsByProvider | undefined>;
export type InternalDetailsAPI = (env: BasicEnvInfo) => Promise<PythonEnvInfo | undefined>;

export interface IDetailsAPI {
export interface IResolverAPI {
/**
* Carries API to check if an environment can be recognized by the provider. Providers
* which returns details about an {@link EnvSource} are expected to
* provide this.
*/
readonly sourceIdentifier: IIdentifierAPI | undefined;
/**
* This is only called if the provider:
* * Can identify the environment.
* * Or can iterate out the environment.
* Returns details or `undefined` if it was found if env is invalid.
* This is only called if:
* * The provider can identify the environment.
* * To get more details out of an environment already iterated by the provider.
*/
getEnvironmentDetails: ProposedDetailsAPI;
}

export type IResolverAPI = IDetailsAPI | (IDetailsAPI & IIdentifierAPI);

/**
* Identifier need not be registered
*/
interface IIdentifierAPI {
/**
* Environment source the provider identifies.
Expand All @@ -98,6 +98,7 @@ interface IIdentifierAPI {
}

export interface IInternalResolverAPI {
readonly kindIdentifier: IInternalIdentifierAPI | undefined;
getEnvironmentDetails: InternalDetailsAPI;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export class PythonEnvsResolver implements IResolvingLocator {
if (this.parentLocator.addNewLocator) {
this.parentLocator.addNewLocator(provider.createLocator, metadata);
}
registerIdentifier(metadata.environments.envKinds[0], provider.canIdentifyEnvironment);
if (provider.kindIdentifier) {
registerIdentifier(provider.kindIdentifier.envKind, provider.kindIdentifier.canIdentifyEnvironment);
}
registerResolver(metadata.environments.envKinds[0], provider.getEnvironmentDetails);
}

Expand Down
8 changes: 6 additions & 2 deletions src/client/pythonEnvironments/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ export function convertProviderMetaData(proposed: EnvironmentProviderMetadata):

function convertResolverAPI(proposed: IResolverAPI): IInternalResolverAPI {
return {
envKind: proposed.envSource ? convertKind(proposed.envSource) : undefined,
canIdentifyEnvironment: proposed.canIdentifyEnvironment,
kindIdentifier: proposed.sourceIdentifier
? {
envKind: convertKind(proposed.sourceIdentifier.envSource),
canIdentifyEnvironment: proposed.sourceIdentifier.canIdentifyEnvironment,
}
: undefined,
getEnvironmentDetails: convertDetailsAPI(proposed.getEnvironmentDetails),
};
}
Expand Down

0 comments on commit f88636a

Please sign in to comment.