(params: {
cwd: string
fs: CodebuffFileSystem
logger: Logger
})
| 201 | } |
| 202 | |
| 203 | function createDiscoveredProjectReader(params: { |
| 204 | cwd: string |
| 205 | fs: CodebuffFileSystem |
| 206 | logger: Logger |
| 207 | }): (filePath: string) => Promise<string | null> { |
| 208 | const { cwd, fs, logger } = params |
| 209 | |
| 210 | return async (filePath: string) => { |
| 211 | const fullPath = path.join(cwd, filePath) |
| 212 | try { |
| 213 | const stats = await fs.stat(fullPath) |
| 214 | if (getFileSize(stats) > MAX_DISCOVERED_PROJECT_READ_BYTES) { |
| 215 | return null |
| 216 | } |
| 217 | return await fs.readFile(fullPath, 'utf8') |
| 218 | } catch (error) { |
| 219 | logger.debug?.( |
| 220 | { filePath, error: getErrorObject(error) }, |
| 221 | 'Failed to read discovered project file for symbol scoring', |
| 222 | ) |
| 223 | return null |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | function getFileSize(stats: Awaited<ReturnType<CodebuffFileSystem['stat']>>) { |
| 229 | return typeof stats.size === 'number' ? stats.size : 0 |
no test coverage detected