mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-12-05 08:15:41 -08:00
Tell a failed macOS folder picker from a cancel, and start Browse at a folder that exists
AI Assisted
This commit is contained in:
1 parent
91479b21a1
commit
ddbc85f73d
5 files changed
+202
-42
No files matched your search
@@ -68,6 +68,27 @@ export function specKey(specDir) {
|
||||
.replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
function isFolder(p) {
|
||||
try {
|
||||
return fs.statSync(p).isDirectory();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Where the picker opens: beside the last folder added, else the original, else
|
||||
// `fallback`. A start deleted on disk walks up to its nearest folder still there,
|
||||
// since a picker cannot open at a missing folder and would fail as unavailable.
|
||||
export function pickerStart(ws, fallback) {
|
||||
const added = ws.folders.filter((f) => !f.original);
|
||||
const wanted = added.length ? path.dirname(added[added.length - 1].path) : ws.folders[0]?.path || fallback;
|
||||
for (let dir = wanted; dir; dir = path.dirname(dir)) {
|
||||
if (isFolder(dir)) return dir;
|
||||
if (path.dirname(dir) === dir) break;
|
||||
}
|
||||
return isFolder(fallback) ? fallback : os.homedir();
|
||||
}
|
||||
|
||||
function readStore() {
|
||||
const saved = readJson(WORKSPACES_FILE, null);
|
||||
return saved && typeof saved.projects === "object" && saved.projects ? saved : { projects: {} };
|
||||
@@ -325,14 +346,6 @@ export function serverWorkspace(ctx) {
|
||||
if ((ws.scope || "") !== spec) setScope(ws, spec, "current");
|
||||
}
|
||||
|
||||
function isFolder(p) {
|
||||
try {
|
||||
return fs.statSync(p).isDirectory();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// A folder deleted on disk is marked missing, and unmarked when it comes back.
|
||||
function checkFolders(ws) {
|
||||
ws.missing = ws.missing || [];
|
||||
@@ -432,12 +445,6 @@ export function serverWorkspace(ctx) {
|
||||
return [200, { ok: true }];
|
||||
}
|
||||
|
||||
// Where the picker opens: beside the last folder added, else the original.
|
||||
function pickerStart(ws) {
|
||||
const added = ws.folders.filter((f) => !f.original);
|
||||
return added.length ? path.dirname(added[added.length - 1].path) : ws.folders[0]?.path || sessionWorktree() || project;
|
||||
}
|
||||
|
||||
// One picker at a time. Spawned, never spawnSync: the dialog can sit open for
|
||||
// minutes, and every poll, chat message and `wait` health check has to keep
|
||||
// being answered meanwhile.
|
||||
@@ -452,7 +459,7 @@ export function serverWorkspace(ctx) {
|
||||
// Tests only: stands in for the person, so no dialog ever opens.
|
||||
const echo = process.env.PLAN2CODE_PICKER_ECHO;
|
||||
if (echo) return Promise.resolve([200, echo === "-" ? { cancelled: true } : { path: echo }]);
|
||||
const start = pickerStart(ws);
|
||||
const start = pickerStart(ws, sessionWorktree() || project);
|
||||
if (!pickerCommand(start, WORKSPACE_PICKER_PROMPT)) return Promise.resolve([404, { reason: "no-picker" }]);
|
||||
pickerBusy = true;
|
||||
return pickFolder(start, WORKSPACE_PICKER_PROMPT)
|
||||
|
||||
Reference in new issue
Block a user