( node: TreeNode, depth: number, openSet: ReadonlySet<string>, acc: Row[], )
| 195 | }; |
| 196 | |
| 197 | const flattenTree = ( |
| 198 | node: TreeNode, |
| 199 | depth: number, |
| 200 | openSet: ReadonlySet<string>, |
| 201 | acc: Row[], |
| 202 | ): void => { |
| 203 | const sorted = [...node.children.values()].sort((a, b) => a.segment.localeCompare(b.segment)); |
| 204 | for (const child of sorted) { |
| 205 | const hasChildren = child.children.size > 0; |
| 206 | const isLeaf = !!child.tool && !hasChildren; |
| 207 | |
| 208 | if (isLeaf) { |
| 209 | acc.push({ kind: "leaf", depth, path: child.path, tool: child.tool! }); |
| 210 | continue; |
| 211 | } |
| 212 | |
| 213 | const open = openSet.has(child.path); |
| 214 | acc.push({ |
| 215 | kind: "group", |
| 216 | depth, |
| 217 | path: child.path, |
| 218 | segment: child.segment, |
| 219 | count: countLeaves(child), |
| 220 | open, |
| 221 | }); |
| 222 | if (open) { |
| 223 | flattenTree(child, depth + 1, openSet, acc); |
| 224 | } |
| 225 | } |
| 226 | }; |
| 227 | |
| 228 | // --------------------------------------------------------------------------- |
| 229 | // Highlight |
no test coverage detected