Skip to content

Commit

Permalink
Apply API recommendations for Create Env API
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig committed Aug 11, 2023
1 parent ab8d3b2 commit 43987f0
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 32 deletions.
17 changes: 9 additions & 8 deletions src/client/pythonEnvironments/creation/createEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ function fireStartedEvent(options?: CreateEnvironmentOptions): void {
}

function fireExitedEvent(result?: CreateEnvironmentResult, options?: CreateEnvironmentOptions, error?: Error): void {
onCreateEnvironmentExitedEvent.fire({
options,
workspaceFolder: result?.workspaceFolder,
path: result?.path,
action: result?.action,
error: error || result?.error,
});
startedEventCount -= 1;
if (result) {
onCreateEnvironmentExitedEvent.fire({ options, ...result });
} else if (error) {
onCreateEnvironmentExitedEvent.fire({ options, error });
}
}

export function getCreationEvents(): {
Expand Down Expand Up @@ -195,5 +193,8 @@ export async function handleCreateEnvironmentCommand(
}
}

return result;
if (result) {
return Object.freeze(result);
}
return undefined;
}
91 changes: 67 additions & 24 deletions src/client/pythonEnvironments/creation/proposed.createEnvApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,80 @@ export interface EnvironmentWillCreateEvent {
options: CreateEnvironmentOptions | undefined;
}

export type CreateEnvironmentResult =
| {
/**
* Workspace folder associated with the environment.
*/
readonly workspaceFolder?: WorkspaceFolder;

/**
* Path to the executable python in the environment
*/
readonly path: string;

/**
* User action that resulted in exit from the create environment flow.
*/
readonly action?: CreateEnvironmentUserActions;

/**
* Error if any occurred during environment creation.
*/
readonly error?: Error;
}
| {
/**
* Workspace folder associated with the environment.
*/
readonly workspaceFolder?: WorkspaceFolder;

/**
* Path to the executable python in the environment
*/
readonly path?: string;

/**
* User action that resulted in exit from the create environment flow.
*/
readonly action: CreateEnvironmentUserActions;

/**
* Error if any occurred during environment creation.
*/
readonly error?: Error;
}
| {
/**
* Workspace folder associated with the environment.
*/
readonly workspaceFolder?: WorkspaceFolder;

/**
* Path to the executable python in the environment
*/
readonly path?: string;

/**
* User action that resulted in exit from the create environment flow.
*/
readonly action?: CreateEnvironmentUserActions;

/**
* Error if any occurred during environment creation.
*/
readonly error: Error;
};

/**
* Params passed on `onDidCreateEnvironment` event handler.
*/
export interface EnvironmentDidCreateEvent extends CreateEnvironmentResult {
export type EnvironmentDidCreateEvent = CreateEnvironmentResult & {
/**
* Options used to create the Python environment.
*/
options: CreateEnvironmentOptions | undefined;
}

export interface CreateEnvironmentResult {
/**
* Workspace folder associated with the environment.
*/
workspaceFolder: WorkspaceFolder | undefined;

/**
* Path to the executable python in the environment
*/
path: string | undefined;

/**
* User action that resulted in exit from the create environment flow.
*/
action: CreateEnvironmentUserActions | undefined;

/**
* Error if any occurred during environment creation.
*/
error: Error | undefined;
}
};

/**
* Extensions that want to contribute their own environment creation can do that by registering an object
Expand Down

0 comments on commit 43987f0

Please sign in to comment.