MCPcopy Create free account
hub / github.com/bearlyai/OpenADE / buildTree

Function buildTree

projects/electron/src/modules/code/files.ts:341–367  ·  view source on GitHub ↗
(files: string[])

Source from the content-addressed store, hash-verified

339// ============================================================================
340
341function buildTree(files: string[]): TreeNode {
342 const root: TreeNode = { name: "", isDir: true, fullPath: "", children: new Map() }
343
344 for (const filePath of files) {
345 const parts = filePath.split("/")
346 let current = root
347 let pathSoFar = ""
348
349 for (let i = 0; i < parts.length; i++) {
350 const part = parts[i]
351 pathSoFar = pathSoFar ? `${pathSoFar}/${part}` : part
352 const isLast = i === parts.length - 1
353
354 if (!current.children.has(part)) {
355 current.children.set(part, {
356 name: part,
357 isDir: !isLast,
358 fullPath: pathSoFar,
359 children: new Map(),
360 })
361 }
362 current = current.children.get(part)!
363 }
364 }
365
366 return root
367}
368
369function lookupTree(root: TreeNode, treePath: string): TreeNode | null {
370 if (!treePath) return root

Callers 1

getFileListFunction · 0.85

Calls 3

hasMethod · 0.80
setMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected