mirror of
https://github.com/stablyai/orca.git
synced 2026-09-29 00:02:56 +00:00
* 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>
38 lines
1.2 KiB
TypeScript
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)
|
|
}
|