From 950dd5df3301cb1395a15b186a438506aed11968 Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Wed, 23 Apr 2025 10:14:53 -0700 Subject: [PATCH 1/3] update return type of project create --- src/api.ts | 13 ++++++++----- src/features/creators/existingProjects.ts | 4 +++- src/features/envCommands.ts | 11 ++++++++++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/api.ts b/src/api.ts index 924d955a..539c3f97 100644 --- a/src/api.ts +++ b/src/api.ts @@ -702,11 +702,14 @@ export interface PythonProjectCreator { readonly iconPath?: IconPath; /** - * 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. - */ - create(options?: PythonProjectCreatorOptions): Promise; + * Creates a new Python project(s) or, if files are not a project, returns Uri(s) to the created files. + * @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. + */ + create(options?: PythonProjectCreatorOptions): Promise; } /** diff --git a/src/features/creators/existingProjects.ts b/src/features/creators/existingProjects.ts index a3e5e223..9aa38c55 100644 --- a/src/features/creators/existingProjects.ts +++ b/src/features/creators/existingProjects.ts @@ -13,7 +13,9 @@ export class ExistingProjects implements PythonProjectCreator { constructor(private readonly pm: PythonProjectManager) {} - async create(_options?: PythonProjectCreatorOptions): Promise { + async create( + _options?: PythonProjectCreatorOptions, + ): Promise { const results = await showOpenDialog({ canSelectFiles: true, canSelectFolders: true, diff --git a/src/features/envCommands.ts b/src/features/envCommands.ts index 3417a31c..12ebb776 100644 --- a/src/features/envCommands.ts +++ b/src/features/envCommands.ts @@ -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) { @@ -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]; } From 2020167926cc0293f3e04c6369756adeec2ae0d3 Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Thu, 24 Apr 2025 09:21:24 -0700 Subject: [PATCH 2/3] add in message about def of python project --- src/api.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/api.ts b/src/api.ts index 539c3f97..4df235df 100644 --- a/src/api.ts +++ b/src/api.ts @@ -703,6 +703,7 @@ export interface PythonProjectCreator { /** * Creates a new Python project(s) or, if files are not a project, returns Uri(s) to the created files. + * 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. From 33bc818d33c05ad4bfa585b339df5292f92df40b Mon Sep 17 00:00:00 2001 From: eleanorjboyd <26030610+eleanorjboyd@users.noreply.github.com> Date: Thu, 24 Apr 2025 09:22:39 -0700 Subject: [PATCH 3/3] fomatting --- src/api.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/api.ts b/src/api.ts index 25252ade..ec63a156 100644 --- a/src/api.ts +++ b/src/api.ts @@ -716,9 +716,9 @@ export interface PythonProjectCreator { * - undefined: if project creation fails. */ create(options?: PythonProjectCreatorOptions): Promise; - - /** - * A flag indicating whether the project creator supports quick create where no user input is required. + + /** + * A flag indicating whether the project creator supports quick create where no user input is required. */ readonly supportsQuickCreate?: boolean; }