@@ -4,7 +4,7 @@ import { commands, l10n, MarkdownString, QuickInputButtons, Uri, window, workspa
4
4
import { PythonProject , PythonProjectCreator , PythonProjectCreatorOptions } from '../../api' ;
5
5
import { NEW_PROJECT_TEMPLATES_FOLDER } from '../../common/constants' ;
6
6
import { showInputBoxWithButtons } from '../../common/window.apis' ;
7
- import { EnvironmentManagers } from '../../internal.api' ;
7
+ import { EnvironmentManagers , PythonProjectManager } from '../../internal.api' ;
8
8
import {
9
9
isCopilotInstalled ,
10
10
manageCopilotInstructionsFile ,
@@ -20,9 +20,12 @@ export class NewPackageProject implements PythonProjectCreator {
20
20
public readonly description = l10n . t ( 'Creates a package folder in your current workspace' ) ;
21
21
public readonly tooltip = new MarkdownString ( l10n . t ( 'Create a new Python package' ) ) ;
22
22
23
- constructor ( private readonly envManagers : EnvironmentManagers ) { }
23
+ constructor (
24
+ private readonly envManagers : EnvironmentManagers ,
25
+ private readonly projectManager : PythonProjectManager ,
26
+ ) { }
24
27
25
- async create ( options ?: PythonProjectCreatorOptions ) : Promise < PythonProject | undefined > {
28
+ async create ( options ?: PythonProjectCreatorOptions ) : Promise < PythonProject | Uri | undefined > {
26
29
let packageName = options ?. name ;
27
30
let createVenv : boolean | undefined ;
28
31
let createCopilotInstructions : boolean | undefined ;
@@ -109,7 +112,15 @@ export class NewPackageProject implements PythonProjectCreator {
109
112
await replaceInFilesAndNames ( projectDestinationFolder , 'package_name' , packageName ) ;
110
113
111
114
// 4. Create virtual environment if requested
115
+ let createdPackage : PythonProject | undefined ;
112
116
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 ) ;
113
124
await quickCreateNewVenv ( this . envManagers , projectDestinationFolder ) ;
114
125
}
115
126
@@ -141,11 +152,13 @@ export class NewPackageProject implements PythonProjectCreator {
141
152
} ;
142
153
await manageLaunchJsonFile ( destRoot , JSON . stringify ( launchJsonConfig ) ) ;
143
154
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
+ }
149
162
}
150
163
}
151
164
}
0 commit comments