( dirPath: string, )
| 82 | * Uses LRU cache to avoid repeated filesystem calls |
| 83 | */ |
| 84 | export 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 |
no test coverage detected