MCPcopy Create free account
hub / github.com/Noumena-Network/code / getDirectoryNamesAsync

Function getDirectoryNamesAsync

src/hooks/fileSuggestions.ts:464–479  ·  view source on GitHub ↗
(
  files: string[],
)

Source from the content-addressed store, hash-verified

462 * the main thread for >10ms at a time.
463 */
464export async function getDirectoryNamesAsync(
465 files: string[],
466): Promise<string[]> {
467 const directoryNames = new Set<string>()
468 // Time-based chunking: yield after CHUNK_MS of work so slow machines get
469 // smaller chunks and stay responsive.
470 let chunkStart = performance.now()
471 for (let i = 0; i < files.length; i++) {
472 collectDirectoryNames(files, i, i + 1, directoryNames)
473 if ((i & 0xff) === 0xff && performance.now() - chunkStart > CHUNK_MS) {
474 await yieldToEventLoop()
475 chunkStart = performance.now()
476 }
477 }
478 return [...directoryNames].map(d => d + path.sep)
479}
480
481function collectDirectoryNames(
482 files: string[],

Callers 2

getPathsForSuggestionsFunction · 0.85

Calls 2

collectDirectoryNamesFunction · 0.85
yieldToEventLoopFunction · 0.85

Tested by

no test coverage detected