Skip to content

Commit 069a2e8

Browse files
committed
update for existing project creation
1 parent 5179dbd commit 069a2e8

3 files changed

Lines changed: 51 additions & 5 deletions

File tree

src/features/creators/autoFindProjects.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import * as path from 'path';
22
import { Uri } from 'vscode';
3-
import { showQuickPickWithButtons } from '../../common/window.apis';
3+
import { showQuickPickWithButtons, showWarningMessage } from '../../common/window.apis';
44
import { ProjectCreatorString } from '../../common/localize';
55
import { PythonProject, PythonProjectCreator, PythonProjectCreatorOptions } from '../../api';
66
import { PythonProjectManager } from '../../internal.api';
77
import { showErrorMessage } from '../../common/errors/utils';
88
import { findFiles } from '../../common/workspace.apis';
9+
import { traceInfo } from '../../common/logging';
910

1011
function getUniqueUri(uris: Uri[]): {
1112
label: string;
@@ -68,8 +69,9 @@ export class AutoFindProjects implements PythonProjectCreator {
6869
const filtered = files.filter((uri) => {
6970
const p = this.pm.get(uri);
7071
if (p) {
71-
// If there ia already a project with the same path, skip it.
72-
// If there is a project with the same parent path, skip it.
72+
// Skip this project if:
73+
// 1. There's already a project registered with exactly the same path
74+
// 2. There's already a project registered with this project's parent directory path
7375
const np = path.normalize(p.uri.fsPath);
7476
const nf = path.normalize(uri.fsPath);
7577
const nfp = path.dirname(nf);
@@ -79,11 +81,20 @@ export class AutoFindProjects implements PythonProjectCreator {
7981
});
8082

8183
if (filtered.length === 0) {
84+
// No new projects found that are not already in the project manager
85+
traceInfo('All discovered projects are already registered in the project manager');
86+
setImmediate(() => {
87+
showWarningMessage('No new projects found');
88+
});
8289
return;
8390
}
8491

92+
traceInfo(`Found ${filtered.length} new potential projects that aren't already registered`);
93+
8594
const projects = await pickProjects(filtered);
8695
if (!projects || projects.length === 0) {
96+
// User cancelled the selection.
97+
traceInfo('User cancelled project selection.');
8798
return;
8899
}
89100

src/features/creators/existingProjects.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import * as path from 'path';
22
import { PythonProject, PythonProjectCreator, PythonProjectCreatorOptions } from '../../api';
33
import { ProjectCreatorString } from '../../common/localize';
4-
import { showOpenDialog } from '../../common/window.apis';
4+
import { showOpenDialog, showWarningMessage } from '../../common/window.apis';
5+
import { PythonProjectManager } from '../../internal.api';
6+
import { traceInfo } from '../../common/logging';
57

68
export class ExistingProjects implements PythonProjectCreator {
79
public readonly name = 'existingProjects';
810
public readonly displayName = ProjectCreatorString.addExistingProjects;
911

12+
constructor(private readonly pm: PythonProjectManager) {}
13+
1014
async create(_options?: PythonProjectCreatorOptions): Promise<PythonProject | PythonProject[] | undefined> {
1115
const results = await showOpenDialog({
1216
canSelectFiles: true,
@@ -22,7 +26,30 @@ export class ExistingProjects implements PythonProjectCreator {
2226
return;
2327
}
2428

25-
return results.map((r) => ({
29+
// do we have any limitations that need to be applied here?
30+
// like selected folder not child of workspace folder?
31+
32+
const filtered = results.filter((uri) => {
33+
const p = this.pm.get(uri);
34+
if (p) {
35+
// Skip this project if there's already a project registered with exactly the same path
36+
const np = path.normalize(p.uri.fsPath);
37+
const nf = path.normalize(uri.fsPath);
38+
return np !== nf;
39+
}
40+
return true;
41+
});
42+
43+
if (filtered.length === 0) {
44+
// No new projects found that are not already in the project manager
45+
traceInfo('All discovered projects are already registered in the project manager');
46+
setImmediate(() => {
47+
showWarningMessage('No new projects found');
48+
});
49+
return;
50+
}
51+
52+
return filtered.map((r) => ({
2653
name: path.basename(r.fsPath),
2754
uri: r,
2855
}));

src/features/envCommands.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,14 @@ export async function addPythonProject(
348348
return;
349349
}
350350

351+
if (
352+
resource instanceof ProjectPackageRootTreeItem ||
353+
resource instanceof ProjectPackage ||
354+
resource instanceof ProjectEnvironment
355+
) {
356+
await addPythonProject(undefined, wm, em, pc);
357+
}
358+
351359
if (resource instanceof Uri) {
352360
const uri = resource as Uri;
353361
const envManagerId = getDefaultEnvManagerSetting(wm, uri);

0 commit comments

Comments
 (0)