Selaa lähdekoodia

New Project creates a sibling folder and offers to switch

files.resolve() without options never populates children, so the
empty-root check always scaffolded into the open project. New
projects now always get their own folder (sibling of the workspace,
in place only when genuinely empty), with a Switch/Stay prompt that
opens the new project on confirmation.
Eric Streit 5 päivää sitten
vanhempi
commit
7353b4386b

+ 5 - 8
PLAN.md

@@ -1,17 +1,14 @@
-# Plan — next steps (from v0.30.0)
+# Plan — next steps (from v0.31.0)
 
-Status: IDE complete through v0.30.0, distributables fresh at v0.24.0
+Status: IDE complete through v0.31.0, distributables fresh at v0.24.0
 (AppImage + deb in gitignored `apps/electron/dist/`). Tree clean except
 this file; all tags local.
 
 ## Done since the last plan
 
-- v0.29.0 explorer creation commands (definition-only modules,
-  New Folder Here, workspace-root fallback).
-- v0.30.0 project activity icon (dedicated view container; tree root
-  needs explicit height or the virtual list measures zero),
-  Project menubar menu (New/Open/Switch/Close), recent-projects list
-  with Switch picker, definition-only + folder creation (above).
+- v0.31.0 New Project folder fix (own sibling folder + switch prompt;
+  plain `resolve()` never lists children, so it always scaffolded
+  in place).
 
 ## Next, in priority order
 

+ 30 - 3
extensions/modula2-project/src/browser/modula2-project-frontend-module.ts

@@ -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). */