Skip to content

Commit 04dac71

Browse files
authored
update return type of project create (microsoft#334)
update the API surface to change return type of the project creator
1 parent ed61d79 commit 04dac71

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

src/api.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -707,16 +707,20 @@ export interface PythonProjectCreator {
707707
readonly iconPath?: IconPath;
708708

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

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

722726
/**

src/features/creators/existingProjects.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ export class ExistingProjects implements PythonProjectCreator {
1313

1414
constructor(private readonly pm: PythonProjectManager) {}
1515

16-
async create(_options?: PythonProjectCreatorOptions): Promise<PythonProject | PythonProject[] | undefined> {
16+
async create(
17+
_options?: PythonProjectCreatorOptions,
18+
): Promise<PythonProject | PythonProject[] | Uri | Uri[] | undefined> {
1719
const results = await showOpenDialog({
1820
canSelectFiles: true,
1921
canSelectFolders: true,

src/features/envCommands.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ export async function addPythonProject(
368368
return;
369369
}
370370

371-
let results: PythonProject | PythonProject[] | undefined;
371+
let results: PythonProject | PythonProject[] | Uri | Uri[] | undefined;
372372
try {
373373
results = await creator.create();
374374
if (results === undefined) {
@@ -381,6 +381,15 @@ export async function addPythonProject(
381381
throw ex;
382382
}
383383

384+
if (
385+
results instanceof Uri ||
386+
(Array.isArray(results) && results.length > 0 && results.every((r) => r instanceof Uri))
387+
) {
388+
// the results are Uris, which means they aren't projects and shouldn't be added
389+
return;
390+
}
391+
results = results as PythonProject | PythonProject[];
392+
384393
if (!Array.isArray(results)) {
385394
results = [results];
386395
}

0 commit comments

Comments
 (0)