|
1 | 1 | import { commands, ExtensionContext, LogOutputChannel, Terminal, Uri, window } from 'vscode'; |
2 | | -import { PythonEnvironment, PythonEnvironmentApi } from './api'; |
| 2 | +import { PythonEnvironment, PythonEnvironmentApi, PythonProjectCreator, PythonProjectCreatorOptions } from './api'; |
3 | 3 | import { ensureCorrectVersion } from './common/extVersion'; |
4 | 4 | import { registerTools } from './common/lm.apis'; |
5 | 5 | import { registerLogger, traceError, traceInfo } from './common/logging'; |
@@ -114,13 +114,21 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron |
114 | 114 | context.subscriptions.push(terminalActivation, terminalManager); |
115 | 115 |
|
116 | 116 | const projectCreators: ProjectCreators = new ProjectCreatorsImpl(); |
| 117 | + const abc = new NewScriptProject(); |
117 | 118 | context.subscriptions.push( |
118 | 119 | projectCreators, |
119 | 120 | projectCreators.registerPythonProjectCreator(new ExistingProjects(projectManager)), |
120 | 121 | projectCreators.registerPythonProjectCreator(new AutoFindProjects(projectManager)), |
121 | 122 | projectCreators.registerPythonProjectCreator(new NewPackageProject(envManagers, projectManager)), |
122 | | - projectCreators.registerPythonProjectCreator(new NewScriptProject()), |
| 123 | + |
| 124 | + projectCreators.registerPythonProjectCreator(abc), |
123 | 125 | ); |
| 126 | + const cd: PythonProjectCreatorOptions = { |
| 127 | + name: abc.name, |
| 128 | + rootUri: context.extensionUri, |
| 129 | + quickCreate: true, |
| 130 | + }; |
| 131 | + abc.create(cd); |
124 | 132 |
|
125 | 133 | setPythonApi(envManagers, projectManager, projectCreators, terminalManager, envVarManager); |
126 | 134 | const api = await getPythonApi(); |
@@ -248,12 +256,37 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron |
248 | 256 | await terminalManager.deactivate(terminal); |
249 | 257 | } |
250 | 258 | }), |
251 | | - commands.registerCommand('python-envs.createNewProjectFromTemplate', async () => { |
252 | | - const selected = await newProjectSelection(projectCreators.getProjectCreators()); |
253 | | - if (selected) { |
254 | | - await selected.create(); |
255 | | - } |
256 | | - }), |
| 259 | + commands.registerCommand( |
| 260 | + 'python-envs.createNewProjectFromTemplate', |
| 261 | + async (projectType: string, quickCreate: boolean, newProjectName: string, newProjectPath: string) => { |
| 262 | + if (quickCreate) { |
| 263 | + if (!projectType || !newProjectName || !newProjectPath) { |
| 264 | + throw new Error('Project type, name, and path are required for quick create.'); |
| 265 | + } |
| 266 | + const creators = projectCreators.getProjectCreators(); |
| 267 | + let selected: PythonProjectCreator | undefined; |
| 268 | + if (projectType === 'python-package') { |
| 269 | + selected = creators.find((c) => c.name === 'newPackage'); |
| 270 | + } |
| 271 | + if (projectType === 'python-script') { |
| 272 | + selected = creators.find((c) => c.name === 'newScript'); |
| 273 | + } |
| 274 | + if (!selected) { |
| 275 | + throw new Error(`Project creator for type "${projectType}" not found.`); |
| 276 | + } |
| 277 | + await selected.create({ |
| 278 | + quickCreate: true, |
| 279 | + name: newProjectName, |
| 280 | + rootUri: Uri.file(newProjectPath), |
| 281 | + }); |
| 282 | + } else { |
| 283 | + const selected = await newProjectSelection(projectCreators.getProjectCreators()); |
| 284 | + if (selected) { |
| 285 | + await selected.create(); |
| 286 | + } |
| 287 | + } |
| 288 | + }, |
| 289 | + ), |
257 | 290 | terminalActivation.onDidChangeTerminalActivationState(async (e) => { |
258 | 291 | await setActivateMenuButtonContext(e.terminal, e.environment, e.activated); |
259 | 292 | }), |
|
0 commit comments