@@ -4,7 +4,7 @@ import { commands, l10n, MarkdownString, QuickInputButtons, Uri, window, workspa
44import { PythonProject , PythonProjectCreator , PythonProjectCreatorOptions } from '../../api' ;
55import { NEW_PROJECT_TEMPLATES_FOLDER } from '../../common/constants' ;
66import { showInputBoxWithButtons } from '../../common/window.apis' ;
7- import { EnvironmentManagers } from '../../internal.api' ;
7+ import { EnvironmentManagers , PythonProjectManager } from '../../internal.api' ;
88import {
99 isCopilotInstalled ,
1010 manageCopilotInstructionsFile ,
@@ -20,9 +20,12 @@ export class NewPackageProject implements PythonProjectCreator {
2020 public readonly description = l10n . t ( 'Creates a package folder in your current workspace' ) ;
2121 public readonly tooltip = new MarkdownString ( l10n . t ( 'Create a new Python package' ) ) ;
2222
23- constructor ( private readonly envManagers : EnvironmentManagers ) { }
23+ constructor (
24+ private readonly envManagers : EnvironmentManagers ,
25+ private readonly projectManager : PythonProjectManager ,
26+ ) { }
2427
25- async create ( options ?: PythonProjectCreatorOptions ) : Promise < PythonProject | undefined > {
28+ async create ( options ?: PythonProjectCreatorOptions ) : Promise < PythonProject | Uri | undefined > {
2629 let packageName = options ?. name ;
2730 let createVenv : boolean | undefined ;
2831 let createCopilotInstructions : boolean | undefined ;
@@ -109,7 +112,15 @@ export class NewPackageProject implements PythonProjectCreator {
109112 await replaceInFilesAndNames ( projectDestinationFolder , 'package_name' , packageName ) ;
110113
111114 // 4. Create virtual environment if requested
115+ let createdPackage : PythonProject | undefined ;
112116 if ( createVenv ) {
117+ createdPackage = {
118+ name : packageName ,
119+ uri : Uri . file ( projectDestinationFolder ) ,
120+ } ;
121+
122+ // add package to list of packages before creating the venv
123+ this . projectManager . add ( createdPackage ) ;
113124 await quickCreateNewVenv ( this . envManagers , projectDestinationFolder ) ;
114125 }
115126
@@ -141,11 +152,13 @@ export class NewPackageProject implements PythonProjectCreator {
141152 } ;
142153 await manageLaunchJsonFile ( destRoot , JSON . stringify ( launchJsonConfig ) ) ;
143154
144- // Return a PythonProject OR Uri (if no venv was created)
145- return {
146- name : packageName ,
147- uri : Uri . file ( projectDestinationFolder ) ,
148- } ;
155+ if ( createdPackage ) {
156+ // return package if created (ie when venv is created)
157+ return createdPackage ;
158+ } else {
159+ // otherwise its not a package and just a folder
160+ return Uri . file ( projectDestinationFolder ) ;
161+ }
149162 }
150163 }
151164}
0 commit comments