Files
orca/src/shared/quick-open-expansion-paths.ts
T
c5669cceb5 fix(quick-open): prune generated dirs in git fallback (#7842)
* fix(quick-open): prune generated dirs in git fallback

* fix(source-control): narrow manual review provider switch

* fix(quick-open): collapse git fallback directories

Co-authored-by: Orca <help@stably.ai>

* fix(quick-open): harden collapsed git directory expansion

Co-authored-by: Orca <help@stably.ai>

* fix(quick-open): close directory expansion races

Co-authored-by: Orca <help@stably.ai>

* perf(quick-open): collapse placeholders efficiently

Co-authored-by: Orca <help@stably.ai>

* fix(quick-open): preserve root and cancellation semantics

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
Co-authored-by: Orca <help@stably.ai>
2026-07-10 03:06:44 -07:00

38 lines
1.2 KiB
TypeScript

/**
* Remove descendant placeholders already covered by an ancestor. Sorting puts
* ancestors first; prefix lookups avoid quadratic scans across sibling paths.
*/
export function collapseQuickOpenExpansionPaths(
expansionPaths: ReadonlyMap<string, boolean>
): [string, boolean][] {
const sortedPaths = Array.from(expansionPaths).sort(([left], [right]) =>
left < right ? -1 : left > right ? 1 : 0
)
const collapsedPaths = new Map<string, boolean>()
for (const [relPath, includeSymlinks] of sortedPaths) {
let ancestorPath: string | undefined
let slashIndex = relPath.indexOf('/')
while (slashIndex !== -1) {
const candidate = relPath.substring(0, slashIndex)
if (collapsedPaths.has(candidate)) {
ancestorPath = candidate
break
}
slashIndex = relPath.indexOf('/', slashIndex + 1)
}
if (ancestorPath) {
// Why: primary and ignored passes can overlap; the ancestor walk covers
// the descendant, but must preserve either pass's symlink-leaf contract.
if (includeSymlinks) {
collapsedPaths.set(ancestorPath, true)
}
continue
}
collapsedPaths.set(relPath, includeSymlinks)
}
return Array.from(collapsedPaths)
}