Skip to content

Commit 259833a

Browse files
authored
feat: enhance project creation with quick create option in new project command (#451)
changes will assist with copilot integration
1 parent 48e45a3 commit 259833a

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

src/extension.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { commands, ExtensionContext, LogOutputChannel, Terminal, Uri, window } from 'vscode';
2-
import { PythonEnvironment, PythonEnvironmentApi } from './api';
2+
import { PythonEnvironment, PythonEnvironmentApi, PythonProjectCreator } from './api';
33
import { ensureCorrectVersion } from './common/extVersion';
44
import { registerTools } from './common/lm.apis';
55
import { registerLogger, traceError, traceInfo } from './common/logging';
@@ -265,12 +265,37 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
265265
await terminalManager.deactivate(terminal);
266266
}
267267
}),
268-
commands.registerCommand('python-envs.createNewProjectFromTemplate', async () => {
269-
const selected = await newProjectSelection(projectCreators.getProjectCreators());
270-
if (selected) {
271-
await selected.create();
272-
}
273-
}),
268+
commands.registerCommand(
269+
'python-envs.createNewProjectFromTemplate',
270+
async (projectType: string, quickCreate: boolean, newProjectName: string, newProjectPath: string) => {
271+
if (quickCreate) {
272+
if (!projectType || !newProjectName || !newProjectPath) {
273+
throw new Error('Project type, name, and path are required for quick create.');
274+
}
275+
const creators = projectCreators.getProjectCreators();
276+
let selected: PythonProjectCreator | undefined;
277+
if (projectType === 'python-package') {
278+
selected = creators.find((c) => c.name === 'newPackage');
279+
}
280+
if (projectType === 'python-script') {
281+
selected = creators.find((c) => c.name === 'newScript');
282+
}
283+
if (!selected) {
284+
throw new Error(`Project creator for type "${projectType}" not found.`);
285+
}
286+
await selected.create({
287+
quickCreate: true,
288+
name: newProjectName,
289+
rootUri: Uri.file(newProjectPath),
290+
});
291+
} else {
292+
const selected = await newProjectSelection(projectCreators.getProjectCreators());
293+
if (selected) {
294+
await selected.create();
295+
}
296+
}
297+
},
298+
),
274299
terminalActivation.onDidChangeTerminalActivationState(async (e) => {
275300
await setActivateMenuButtonContext(e.terminal, e.environment, e.activated);
276301
}),

0 commit comments

Comments
 (0)