Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 14 additions & 3 deletions src/features/creators/autoFindProjects.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as path from 'path';
import { Uri } from 'vscode';
import { showQuickPickWithButtons } from '../../common/window.apis';
import { showQuickPickWithButtons, showWarningMessage } from '../../common/window.apis';
import { ProjectCreatorString } from '../../common/localize';
import { PythonProject, PythonProjectCreator, PythonProjectCreatorOptions } from '../../api';
import { PythonProjectManager } from '../../internal.api';
import { showErrorMessage } from '../../common/errors/utils';
import { findFiles } from '../../common/workspace.apis';
import { traceInfo } from '../../common/logging';

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

if (filtered.length === 0) {
// No new projects found that are not already in the project manager
traceInfo('All discovered projects are already registered in the project manager');
setImmediate(() => {
showWarningMessage('No new projects found');
});
return;
}

traceInfo(`Found ${filtered.length} new potential projects that aren't already registered`);

const projects = await pickProjects(filtered);
if (!projects || projects.length === 0) {
// User cancelled the selection.
traceInfo('User cancelled project selection.');
return;
}

Expand Down
31 changes: 29 additions & 2 deletions src/features/creators/existingProjects.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import * as path from 'path';
import { PythonProject, PythonProjectCreator, PythonProjectCreatorOptions } from '../../api';
import { ProjectCreatorString } from '../../common/localize';
import { showOpenDialog } from '../../common/window.apis';
import { showOpenDialog, showWarningMessage } from '../../common/window.apis';
import { PythonProjectManager } from '../../internal.api';
import { traceInfo } from '../../common/logging';

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

constructor(private readonly pm: PythonProjectManager) {}

async create(_options?: PythonProjectCreatorOptions): Promise<PythonProject | PythonProject[] | undefined> {
const results = await showOpenDialog({
canSelectFiles: true,
Expand All @@ -22,7 +26,30 @@ export class ExistingProjects implements PythonProjectCreator {
return;
}

return results.map((r) => ({
// do we have any limitations that need to be applied here?
// like selected folder not child of workspace folder?

const filtered = results.filter((uri) => {
const p = this.pm.get(uri);
if (p) {
// Skip this project if there's already a project registered with exactly the same path
Comment thread
eleanorjboyd marked this conversation as resolved.
const np = path.normalize(p.uri.fsPath);
const nf = path.normalize(uri.fsPath);
return np !== nf;
}
return true;
});

if (filtered.length === 0) {
// No new projects found that are not already in the project manager
traceInfo('All discovered projects are already registered in the project manager');
setImmediate(() => {
showWarningMessage('No new projects found');
Comment thread
eleanorjboyd marked this conversation as resolved.
});
return;
}

return filtered.map((r) => ({
name: path.basename(r.fsPath),
uri: r,
}));
Expand Down
7 changes: 6 additions & 1 deletion src/features/envCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,12 @@ export async function addPythonProject(
return;
}

if (resource instanceof ProjectPackageRootTreeItem || resource instanceof ProjectPackage) {
if (
resource instanceof ProjectPackageRootTreeItem ||
resource instanceof ProjectPackage ||
resource instanceof ProjectEnvironment
) {
Comment thread
eleanorjboyd marked this conversation as resolved.
Outdated

await addPythonProject(undefined, wm, em, pc);
}

Expand Down
Loading