MCPcopy Create free account
hub / github.com/codeaashu/claude-code / scanDirectory

Function scanDirectory

src/utils/suggestions/directoryCompletion.ts:84–116  ·  view source on GitHub ↗
(
  dirPath: string,
)

Source from the content-addressed store, hash-verified

82 * Uses LRU cache to avoid repeated filesystem calls
83 */
84export async function scanDirectory(
85 dirPath: string,
86): Promise<DirectoryEntry[]> {
87 // Check cache first
88 const cached = directoryCache.get(dirPath)
89 if (cached) {
90 return cached
91 }
92
93 try {
94 // Read directory contents
95 const fs = getFsImplementation()
96 const entries = await fs.readdir(dirPath)
97
98 // Filter for directories only, exclude hidden directories
99 const directories = entries
100 .filter(entry => entry.isDirectory() && !entry.name.startsWith('.'))
101 .map(entry => ({
102 name: entry.name,
103 path: join(dirPath, entry.name),
104 type: 'directory' as const,
105 }))
106 .slice(0, 100) // Limit results for MVP
107
108 // Cache the results
109 directoryCache.set(dirPath, directories)
110
111 return directories
112 } catch (error) {
113 logError(error)
114 return []
115 }
116}
117
118/**
119 * Main function to get directory completion suggestions

Callers 1

getDirectoryCompletionsFunction · 0.85

Calls 4

getFsImplementationFunction · 0.85
getMethod · 0.65
logErrorFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected