Skip to content

update to add all new projects to projects view #537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
projectCreators.registerPythonProjectCreator(new ExistingProjects(projectManager)),
projectCreators.registerPythonProjectCreator(new AutoFindProjects(projectManager)),
projectCreators.registerPythonProjectCreator(new NewPackageProject(envManagers, projectManager)),
projectCreators.registerPythonProjectCreator(new NewScriptProject()),
projectCreators.registerPythonProjectCreator(new NewScriptProject(projectManager)),
);

setPythonApi(envManagers, projectManager, projectCreators, terminalManager, envVarManager);
Expand Down
20 changes: 6 additions & 14 deletions src/features/creators/newPackageProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,8 @@ export class NewPackageProject implements PythonProjectCreator {
await replaceInFilesAndNames(projectDestinationFolder, 'package_name', packageName);

// 4. Create virtual environment if requested
let createdPackage: PythonProject | undefined;
if (createVenv) {
createdPackage = {
name: packageName,
uri: Uri.file(projectDestinationFolder),
};

// add package to list of packages before creating the venv
this.projectManager.add(createdPackage);
await quickCreateNewVenv(this.envManagers, projectDestinationFolder);
}

Expand Down Expand Up @@ -156,13 +149,12 @@ export class NewPackageProject implements PythonProjectCreator {
};
await manageLaunchJsonFile(destRoot, JSON.stringify(launchJsonConfig));

if (createdPackage) {
// return package if created (ie when venv is created)
return createdPackage;
} else {
// otherwise its not a package and just a folder
return Uri.file(projectDestinationFolder);
}
const createdPackage: PythonProject | undefined = {
name: packageName,
uri: Uri.file(projectDestinationFolder),
};
this.projectManager.add(createdPackage);
return createdPackage;
}
return undefined;
}
Expand Down
11 changes: 9 additions & 2 deletions src/features/creators/newScriptProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PythonProject, PythonProjectCreator, PythonProjectCreatorOptions } from
import { NEW_PROJECT_TEMPLATES_FOLDER } from '../../common/constants';
import { traceError } from '../../common/logging';
import { showInputBoxWithButtons } from '../../common/window.apis';
import { PythonProjectManager } from '../../internal.api';
import { isCopilotInstalled, manageCopilotInstructionsFile, replaceInFilesAndNames } from './creationHelpers';

export class NewScriptProject implements PythonProjectCreator {
Expand All @@ -13,7 +14,7 @@ export class NewScriptProject implements PythonProjectCreator {
public readonly description = l10n.t('Creates a new script folder in your current workspace with PEP 723 support');
public readonly tooltip = new MarkdownString(l10n.t('Create a new Python script'));

constructor() {}
constructor(private readonly projectManager: PythonProjectManager) {}

async create(options?: PythonProjectCreatorOptions): Promise<PythonProject | Uri | undefined> {
// quick create (needs name, will always create venv and copilot instructions)
Expand Down Expand Up @@ -113,7 +114,13 @@ export class NewScriptProject implements PythonProjectCreator {
]);
}

return Uri.file(scriptDestination);
// Add the created script to the project manager
const createdScript: PythonProject | undefined = {
name: scriptFileName,
uri: Uri.file(scriptDestination),
};
this.projectManager.add(createdScript);
return createdScript;
}
return undefined;
}
Expand Down
8 changes: 4 additions & 4 deletions src/features/views/treeViewItems.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { TreeItem, TreeItemCollapsibleState, MarkdownString, Command, ThemeIcon } from 'vscode';
import { Command, MarkdownString, ThemeIcon, TreeItem, TreeItemCollapsibleState } from 'vscode';
import { EnvironmentGroupInfo, IconPath, Package, PythonEnvironment, PythonProject } from '../../api';
import { EnvViewStrings } from '../../common/localize';
import { InternalEnvironmentManager, InternalPackageManager } from '../../internal.api';
import { PythonEnvironment, IconPath, Package, PythonProject, EnvironmentGroupInfo } from '../../api';
import { removable } from './utils';
import { isActivatableEnvironment } from '../common/activation';
import { EnvViewStrings } from '../../common/localize';
import { removable } from './utils';

export enum EnvTreeItemKind {
manager = 'python-env-manager',
Expand Down