Skip to content

Commit 97d4611

Browse files
author
Kartik Raj
committed
Change some types
1 parent a6bd637 commit 97d4611

File tree

3 files changed

+53
-35
lines changed

3 files changed

+53
-35
lines changed

src/client/extension.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ import { sendErrorTelemetry, sendStartupTelemetry } from './startupTelemetry';
4242
import { IStartupDurations } from './types';
4343
import { runAfterActivation } from './common/utils/runAfterActivation';
4444
import { IInterpreterService } from './interpreter/contracts';
45-
import { IExtensionApi, IProposedExtensionAPI } from './apiTypes';
45+
import { IExtensionApi } from './apiTypes';
4646
import { buildProposedApi } from './proposedApi';
4747
import { WorkspaceService } from './common/application/workspace';
4848
import { disposeAll } from './common/utils/resourceLifecycle';
49+
import { IProposedExtensionAPI } from './proposedApiTypes';
4950

5051
durations.codeLoadingTime = stopWatch.elapsedTime;
5152

src/client/pythonEnvironments/base/locator.ts

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface EnvironmentDetailsOptions {
2121
/**
2222
* Return details provided by the specific provider, throws error if provider not found.
2323
*/
24-
providerId?: ProviderID;
24+
extensionId?: ExtensionID;
2525
}
2626

2727
export interface EnvironmentDetails {
@@ -30,13 +30,15 @@ export interface EnvironmentDetails {
3030
bitness?: Architecture;
3131
sysPrefix: string;
3232
};
33-
environment?: {
34-
type: EnvType;
35-
name?: string;
36-
path: string;
37-
project?: string; // Any specific project environment is created for.
38-
source: EnvSource[];
39-
};
33+
environment:
34+
| {
35+
type: EnvType;
36+
name?: string;
37+
path: string;
38+
project?: string; // Any specific project environment is created for.
39+
source: EnvSource[];
40+
}
41+
| undefined;
4042
version: StandardVersionInfo & {
4143
sysVersion?: string;
4244
};
@@ -51,9 +53,13 @@ export interface EnvironmentDetails {
5153
* Provider is only required to provide the `executable` key, rest are optional. So construct a type using
5254
* `EnvironmentDetails` where `executable` is the only required key.
5355
*/
54-
type EnvironmentDetailsByProvider = Partial<EnvironmentDetails> & Pick<EnvironmentDetails, 'executable'>;
56+
type EnvironmentDetailsByProvider = Partial<EnvironmentDetails> &
57+
Pick<EnvironmentDetails, 'executable'> &
58+
Pick<EnvironmentDetails, 'environment'>;
5559

56-
export interface IInternalEnvironmentProvider extends ILocatorFactoryAPI, IInternalResolverAPI {}
60+
export type IInternalEnvironmentProvider =
61+
| (ILocatorFactoryAPI & IInternalResolverAPI & IInternalIdentifierAPI)
62+
| (ILocatorFactoryAPI & IInternalResolverAPI);
5763

5864
interface ILocatorFactoryAPI {
5965
/**
@@ -65,38 +71,52 @@ interface ILocatorFactoryAPI {
6571
export type ProposedDetailsAPI = (env: BaseEnvInfo) => Promise<EnvironmentDetailsByProvider | undefined>;
6672
export type InternalDetailsAPI = (env: BasicEnvInfo) => Promise<PythonEnvInfo | undefined>;
6773

68-
export interface IResolverAPI {
69-
/**
70-
* Returns true if provided environment is recognized by the provider.
71-
*/
72-
canIdentifyEnvironment: (path: UniquePathType) => Promise<boolean>;
74+
export interface IDetailsAPI {
7375
/**
74-
* This is only called if this provider can identify the environment.
76+
* This is only called if the provider:
77+
* * Can identify the environment.
78+
* * Iterates out the environment.
7579
* Returns details or `undefined` if it was found if env is invalid.
7680
*/
7781
getEnvironmentDetails: ProposedDetailsAPI;
7882
}
7983

80-
export interface IInternalResolverAPI {
84+
export type IResolverAPI = IDetailsAPI | (IDetailsAPI & IIdentifierAPI);
85+
86+
/**
87+
* Identifier need not be registered
88+
*/
89+
interface IIdentifierAPI {
90+
/**
91+
* Environment source the provider identifies.
92+
*/
93+
readonly envSource: EnvSource;
8194
/**
8295
* Returns true if provided environment is recognized by the provider.
8396
*/
8497
canIdentifyEnvironment: (path: UniquePathType) => Promise<boolean>;
98+
}
99+
100+
export interface IInternalResolverAPI {
101+
getEnvironmentDetails: InternalDetailsAPI;
102+
}
103+
104+
interface IInternalIdentifierAPI {
105+
readonly envKind: PythonEnvKind;
85106
/**
86-
* This is only called if this provider can identify the environment.
87-
* Returns details or `undefined` if it was found if env is invalid.
107+
* Returns true if provided environment is recognized by the provider.
88108
*/
89-
getEnvironmentDetails: InternalDetailsAPI;
109+
canIdentifyEnvironment: (path: UniquePathType) => Promise<boolean>;
90110
}
91111

92112
export type ILocatorFactory = IWorkspaceLocatorFactory | INonWorkspaceLocatorFactory;
93113
export type INonWorkspaceLocatorFactory = () => ILocatorAPI;
94114
export type IWorkspaceLocatorFactory = (root: string) => ILocatorAPI;
95115

96-
export interface IEnvironmentProvider extends ILocatorFactoryAPI, IResolverAPI {}
116+
export type IEnvironmentProvider = ILocatorFactoryAPI & IResolverAPI;
97117
export interface ILocatorAPI {
98-
iterEnvs?(): IPythonEnvsIterator<EnvInfo>;
99-
readonly onChanged?: Event<LocatorEnvsChangedEvent>;
118+
iterEnvs(): IPythonEnvsIterator<EnvInfo>;
119+
readonly onChanged: Event<LocatorEnvsChangedEvent>;
100120
}
101121

102122
export type EnvInfo = BaseEnvInfo & {
@@ -108,7 +128,7 @@ export type BaseEnvInfo = {
108128
envPath?: string;
109129
};
110130

111-
type ProviderID = string;
131+
type ExtensionID = string;
112132

113133
/**
114134
* These can be used when querying for a particular env.
@@ -118,11 +138,11 @@ export interface EnvironmentProviderMetadata {
118138
* Details about the environments the locator provides.
119139
* Useful when querying for a particular env.
120140
*/
121-
readonly environments: EnvironmentMetaData;
141+
readonly environments?: EnvironmentMetaData;
122142
/**
123-
* An Identifier for the provider.
143+
* An Identifier for the extension registering the provider.
124144
*/
125-
readonly providerId: ProviderID;
145+
readonly extensionId: ExtensionID;
126146
}
127147

128148
interface InternalEnvironmentMetaData {
@@ -138,10 +158,7 @@ export interface InternalEnvironmentProviderMetadata {
138158
* Useful when querying for a particular env.
139159
*/
140160
readonly environments: InternalEnvironmentMetaData;
141-
/**
142-
* An Identifier for the provider.
143-
*/
144-
readonly providerId: ProviderID;
161+
readonly extensionId: ExtensionID;
145162
}
146163

147164
interface EnvironmentMetaData {
@@ -168,7 +185,6 @@ export enum KnownEnvTypes {
168185
VirtualEnv = 'VirtualEnv',
169186
Conda = 'Conda',
170187
Unknown = 'Unknown',
171-
Global = 'Global',
172188
}
173189

174190
export type EnvSource = KnownEnvSourceTypes | string;

src/client/pythonEnvironments/converter.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,16 @@ export function convertProviderAPI(proposed: IEnvironmentProvider): IInternalEnv
3838

3939
export function convertProviderMetaData(proposed: EnvironmentProviderMetadata): InternalEnvironmentProviderMetadata {
4040
return {
41-
providerId: proposed.providerId,
41+
extensionId: proposed.extensionId,
4242
environments: {
43-
envKinds: proposed.environments.envSources?.map((e) => convertKind(e)) ?? [PythonEnvKind.Unknown],
43+
envKinds: proposed.environments?.envSources?.map((e) => convertKind(e)) ?? [PythonEnvKind.Unknown],
4444
},
4545
};
4646
}
4747

4848
function convertResolverAPI(proposed: IResolverAPI): IInternalResolverAPI {
4949
return {
50+
envKind: proposed.envSource ? convertKind(proposed.envSource) : undefined,
5051
canIdentifyEnvironment: proposed.canIdentifyEnvironment,
5152
getEnvironmentDetails: convertDetailsAPI(proposed.getEnvironmentDetails),
5253
};

0 commit comments

Comments
 (0)