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

Function scanDirectoryForPaths

src/utils/suggestions/directoryCompletion.ts:168–203  ·  view source on GitHub ↗
(
  dirPath: string,
  includeHidden = false,
)

Source from the content-addressed store, hash-verified

166 * Uses LRU cache to avoid repeated filesystem calls
167 */
168export async function scanDirectoryForPaths(
169 dirPath: string,
170 includeHidden = false,
171): Promise<PathEntry[]> {
172 const cacheKey = `${dirPath}:${includeHidden}`
173 const cached = pathCache.get(cacheKey)
174 if (cached) {
175 return cached
176 }
177
178 try {
179 const fs = getFsImplementation()
180 const entries = await fs.readdir(dirPath)
181
182 const paths = entries
183 .filter(entry => includeHidden || !entry.name.startsWith('.'))
184 .map(entry => ({
185 name: entry.name,
186 path: join(dirPath, entry.name),
187 type: entry.isDirectory() ? ('directory' as const) : ('file' as const),
188 }))
189 .sort((a, b) => {
190 // Sort directories first, then alphabetically
191 if (a.type === 'directory' && b.type !== 'directory') return -1
192 if (a.type !== 'directory' && b.type === 'directory') return 1
193 return a.name.localeCompare(b.name)
194 })
195 .slice(0, 100)
196
197 pathCache.set(cacheKey, paths)
198 return paths
199 } catch (error) {
200 logError(error)
201 return []
202 }
203}
204
205/**
206 * Get path completion suggestions for files and directories

Callers 1

getPathCompletionsFunction · 0.85

Calls 4

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

Tested by

no test coverage detected