|
|
@@ -162,13 +162,32 @@ class ProjectCommands implements CommandContribution {
|
|
|
{ placeholder: 'Project template' },
|
|
|
);
|
|
|
if (!template) return;
|
|
|
- // Scaffold at the root when it is empty, else in a subfolder.
|
|
|
+ // A new project always lives in its own folder: a sibling of the open
|
|
|
+ // workspace, or the workspace itself when that is still empty.
|
|
|
let target = root;
|
|
|
+ let sibling = false;
|
|
|
try {
|
|
|
const stat = await this.files.resolve(root);
|
|
|
- if ((stat.children ?? []).length > 0) target = root.resolve(name);
|
|
|
+ if ((stat.children ?? []).length > 0) {
|
|
|
+ target = root.parent.resolve(name);
|
|
|
+ sibling = true;
|
|
|
+ }
|
|
|
} catch {
|
|
|
- target = root.resolve(name);
|
|
|
+ target = root.parent.resolve(name);
|
|
|
+ sibling = true;
|
|
|
+ }
|
|
|
+ if (sibling) {
|
|
|
+ try {
|
|
|
+ if (await this.files.exists(target)) {
|
|
|
+ const openIt = await this.quickInput.showQuickPick(
|
|
|
+ [{ label: `Switch to "${name}"`, value: 'switch' },
|
|
|
+ { label: 'Stay here', value: 'stay' }],
|
|
|
+ { placeholder: `"${name}" already exists next to the open folder.` },
|
|
|
+ );
|
|
|
+ if (openIt?.value === 'switch') this.workspace.open(target);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ } catch { /* fall through and try creating */ }
|
|
|
}
|
|
|
const files = scaffoldFiles(name, template.value);
|
|
|
try {
|
|
|
@@ -189,6 +208,14 @@ class ProjectCommands implements CommandContribution {
|
|
|
}
|
|
|
const where = target.toString() === root.toString() ? 'the open folder' : `the "${name}" folder`;
|
|
|
this.messages.info(`Modula-2: created ${template.label} "${name}" in ${where}. Open modula2.json to review, then Modula-2: Build.`);
|
|
|
+ if (sibling) {
|
|
|
+ const openIt = await this.quickInput.showQuickPick(
|
|
|
+ [{ label: `Switch to "${name}"`, value: 'switch' },
|
|
|
+ { label: 'Stay here', value: 'stay' }],
|
|
|
+ { placeholder: 'New project created.' },
|
|
|
+ );
|
|
|
+ if (openIt?.value === 'switch') this.workspace.open(target);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/** Open a project folder (delegates to the workspace folder dialog). */
|