Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,16 +707,20 @@ export interface PythonProjectCreator {
readonly iconPath?: IconPath;

/**
* A flag indicating whether the project creator supports quick create where no user input is required.
* Creates a new Python project(s) or, if files are not a project, returns Uri(s) to the created files.
Comment thread
eleanorjboyd marked this conversation as resolved.
* Anything that needs its own python environment constitutes a project.
* @param options Optional parameters for creating the Python project.
* @returns A promise that resolves to one of the following:
* - PythonProject or PythonProject[]: when a single or multiple projects are created.
* - Uri or Uri[]: when files are created that do not constitute a project.
* - undefined: if project creation fails.
*/
readonly supportsQuickCreate?: boolean;
create(options?: PythonProjectCreatorOptions): Promise<PythonProject | PythonProject[] | Uri | Uri[] | undefined>;

/**
* Creates a new Python project or projects.
* @param options - Optional parameters for creating the Python project.
* @returns A promise that resolves to a Python project, an array of Python projects, or undefined.
* A flag indicating whether the project creator supports quick create where no user input is required.
*/
create(options?: PythonProjectCreatorOptions): Promise<PythonProject | PythonProject[] | undefined>;
readonly supportsQuickCreate?: boolean;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/features/creators/existingProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ export class ExistingProjects implements PythonProjectCreator {

constructor(private readonly pm: PythonProjectManager) {}

async create(_options?: PythonProjectCreatorOptions): Promise<PythonProject | PythonProject[] | undefined> {
async create(
_options?: PythonProjectCreatorOptions,
): Promise<PythonProject | PythonProject[] | Uri | Uri[] | undefined> {
const results = await showOpenDialog({
canSelectFiles: true,
canSelectFolders: true,
Expand Down
11 changes: 10 additions & 1 deletion src/features/envCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export async function addPythonProject(
return;
}

let results: PythonProject | PythonProject[] | undefined;
let results: PythonProject | PythonProject[] | Uri | Uri[] | undefined;
try {
results = await creator.create();
if (results === undefined) {
Expand All @@ -381,6 +381,15 @@ export async function addPythonProject(
throw ex;
}

if (
results instanceof Uri ||
(Array.isArray(results) && results.length > 0 && results.every((r) => r instanceof Uri))
) {
// the results are Uris, which means they aren't projects and shouldn't be added
return;
}
results = results as PythonProject | PythonProject[];

if (!Array.isArray(results)) {
results = [results];
}
Expand Down