Skip to content

Commit 950dd5d

Browse files
committed
update return type of project create
1 parent 5eaf48e commit 950dd5d

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/api.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,14 @@ export interface PythonProjectCreator {
702702
readonly iconPath?: IconPath;
703703

704704
/**
705-
* Creates a new Python project or projects.
706-
* @param options - Optional parameters for creating the Python project.
707-
* @returns A promise that resolves to a Python project, an array of Python projects, or undefined.
708-
*/
709-
create(options?: PythonProjectCreatorOptions): Promise<PythonProject | PythonProject[] | undefined>;
705+
* Creates a new Python project(s) or, if files are not a project, returns Uri(s) to the created files.
706+
* @param options Optional parameters for creating the Python project.
707+
* @returns A promise that resolves to one of the following:
708+
* - PythonProject or PythonProject[]: when a single or multiple projects are created.
709+
* - Uri or Uri[]: when files are created that do not constitute a project.
710+
* - undefined: if project creation fails.
711+
*/
712+
create(options?: PythonProjectCreatorOptions): Promise<PythonProject | PythonProject[] | Uri | Uri[] | undefined>;
710713
}
711714

712715
/**

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)