diff --git a/src/client/extension.ts b/src/client/extension.ts index 312e99a386831..30da91a0d2ba4 100644 --- a/src/client/extension.ts +++ b/src/client/extension.ts @@ -42,10 +42,11 @@ import { sendErrorTelemetry, sendStartupTelemetry } from './startupTelemetry'; import { IStartupDurations } from './types'; import { runAfterActivation } from './common/utils/runAfterActivation'; import { IInterpreterService } from './interpreter/contracts'; -import { IExtensionApi, IProposedExtensionAPI } from './apiTypes'; +import { IExtensionApi } from './apiTypes'; import { buildProposedApi } from './proposedApi'; import { WorkspaceService } from './common/application/workspace'; import { disposeAll } from './common/utils/resourceLifecycle'; +import { IProposedExtensionAPI } from './proposedApiTypes'; durations.codeLoadingTime = stopWatch.elapsedTime; diff --git a/src/client/pythonEnvironments/base/locator.ts b/src/client/pythonEnvironments/base/locator.ts index 36cde4e56c489..4c436193e205f 100644 --- a/src/client/pythonEnvironments/base/locator.ts +++ b/src/client/pythonEnvironments/base/locator.ts @@ -21,7 +21,7 @@ export interface EnvironmentDetailsOptions { /** * Return details provided by the specific provider, throws error if provider not found. */ - providerId?: ProviderID; + extensionId?: ExtensionID; } export interface EnvironmentDetails { @@ -30,13 +30,15 @@ export interface EnvironmentDetails { bitness?: Architecture; sysPrefix: string; }; - environment?: { - type: EnvType; - name?: string; - path: string; - project?: string; // Any specific project environment is created for. - source: EnvSource[]; - }; + environment: + | { + type: EnvType; + name?: string; + path: string; + project?: string; // Any specific project environment is created for. + source: EnvSource[]; + } + | undefined; version: StandardVersionInfo & { sysVersion?: string; }; @@ -51,9 +53,13 @@ export interface EnvironmentDetails { * Provider is only required to provide the `executable` key, rest are optional. So construct a type using * `EnvironmentDetails` where `executable` is the only required key. */ -type EnvironmentDetailsByProvider = Partial & Pick; +type EnvironmentDetailsByProvider = Partial & + Pick & + Pick; -export interface IInternalEnvironmentProvider extends ILocatorFactoryAPI, IInternalResolverAPI {} +export type IInternalEnvironmentProvider = + | (ILocatorFactoryAPI & IInternalResolverAPI & IInternalIdentifierAPI) + | (ILocatorFactoryAPI & IInternalResolverAPI); interface ILocatorFactoryAPI { /** @@ -65,38 +71,52 @@ interface ILocatorFactoryAPI { export type ProposedDetailsAPI = (env: BaseEnvInfo) => Promise; export type InternalDetailsAPI = (env: BasicEnvInfo) => Promise; -export interface IResolverAPI { - /** - * Returns true if provided environment is recognized by the provider. - */ - canIdentifyEnvironment: (path: UniquePathType) => Promise; +export interface IDetailsAPI { /** - * This is only called if this provider can identify the environment. + * This is only called if the provider: + * * Can identify the environment. + * * Iterates out the environment. * Returns details or `undefined` if it was found if env is invalid. */ getEnvironmentDetails: ProposedDetailsAPI; } -export interface IInternalResolverAPI { +export type IResolverAPI = IDetailsAPI | (IDetailsAPI & IIdentifierAPI); + +/** + * Identifier need not be registered + */ +interface IIdentifierAPI { + /** + * Environment source the provider identifies. + */ + readonly envSource: EnvSource; /** * Returns true if provided environment is recognized by the provider. */ canIdentifyEnvironment: (path: UniquePathType) => Promise; +} + +export interface IInternalResolverAPI { + getEnvironmentDetails: InternalDetailsAPI; +} + +interface IInternalIdentifierAPI { + readonly envKind: PythonEnvKind; /** - * This is only called if this provider can identify the environment. - * Returns details or `undefined` if it was found if env is invalid. + * Returns true if provided environment is recognized by the provider. */ - getEnvironmentDetails: InternalDetailsAPI; + canIdentifyEnvironment: (path: UniquePathType) => Promise; } export type ILocatorFactory = IWorkspaceLocatorFactory | INonWorkspaceLocatorFactory; export type INonWorkspaceLocatorFactory = () => ILocatorAPI; export type IWorkspaceLocatorFactory = (root: string) => ILocatorAPI; -export interface IEnvironmentProvider extends ILocatorFactoryAPI, IResolverAPI {} +export type IEnvironmentProvider = ILocatorFactoryAPI & IResolverAPI; export interface ILocatorAPI { - iterEnvs?(): IPythonEnvsIterator; - readonly onChanged?: Event; + iterEnvs(): IPythonEnvsIterator; + readonly onChanged: Event; } export type EnvInfo = BaseEnvInfo & { @@ -108,7 +128,7 @@ export type BaseEnvInfo = { envPath?: string; }; -type ProviderID = string; +type ExtensionID = string; /** * These can be used when querying for a particular env. @@ -118,11 +138,11 @@ export interface EnvironmentProviderMetadata { * Details about the environments the locator provides. * Useful when querying for a particular env. */ - readonly environments: EnvironmentMetaData; + readonly environments?: EnvironmentMetaData; /** - * An Identifier for the provider. + * An Identifier for the extension registering the provider. */ - readonly providerId: ProviderID; + readonly extensionId: ExtensionID; } interface InternalEnvironmentMetaData { @@ -138,10 +158,7 @@ export interface InternalEnvironmentProviderMetadata { * Useful when querying for a particular env. */ readonly environments: InternalEnvironmentMetaData; - /** - * An Identifier for the provider. - */ - readonly providerId: ProviderID; + readonly extensionId: ExtensionID; } interface EnvironmentMetaData { @@ -168,7 +185,6 @@ export enum KnownEnvTypes { VirtualEnv = 'VirtualEnv', Conda = 'Conda', Unknown = 'Unknown', - Global = 'Global', } export type EnvSource = KnownEnvSourceTypes | string; diff --git a/src/client/pythonEnvironments/converter.ts b/src/client/pythonEnvironments/converter.ts index 8cf13a0ff8acd..99f403858db88 100644 --- a/src/client/pythonEnvironments/converter.ts +++ b/src/client/pythonEnvironments/converter.ts @@ -38,15 +38,16 @@ export function convertProviderAPI(proposed: IEnvironmentProvider): IInternalEnv export function convertProviderMetaData(proposed: EnvironmentProviderMetadata): InternalEnvironmentProviderMetadata { return { - providerId: proposed.providerId, + extensionId: proposed.extensionId, environments: { - envKinds: proposed.environments.envSources?.map((e) => convertKind(e)) ?? [PythonEnvKind.Unknown], + envKinds: proposed.environments?.envSources?.map((e) => convertKind(e)) ?? [PythonEnvKind.Unknown], }, }; } function convertResolverAPI(proposed: IResolverAPI): IInternalResolverAPI { return { + envKind: proposed.envSource ? convertKind(proposed.envSource) : undefined, canIdentifyEnvironment: proposed.canIdentifyEnvironment, getEnvironmentDetails: convertDetailsAPI(proposed.getEnvironmentDetails), };