Index just a single file (used for live updates after a write_file).
(filePath: string)
| 142 | |
| 143 | /** Index just a single file (used for live updates after a write_file). */ |
| 144 | async indexFile(filePath: string): Promise<{ symbols: number } | null> { |
| 145 | try { |
| 146 | const stat = await fs.stat(filePath); |
| 147 | const lang = detectLanguage(filePath); |
| 148 | if (!lang || stat.size > MAX_FILE_SIZE) return null; |
| 149 | const buf = await fs.readFile(filePath); |
| 150 | if (isBinaryBuffer(buf)) return null; |
| 151 | const contentHash = crypto.createHash('sha256').update(buf).digest('hex').slice(0, 16); |
| 152 | const source = buf.toString('utf-8'); |
| 153 | const symbols = await extractSymbols(filePath, source); |
| 154 | this.db.replaceFileSymbols(filePath, lang, stat.mtimeMs, stat.size, contentHash, symbols); |
| 155 | return { symbols: symbols.length }; |
| 156 | } catch (e: any) { |
| 157 | logger.debug('indexFile failed', { filePath, err: e.message }); |
| 158 | return null; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | private async walk(dir: string, onFile: (path: string) => void): Promise<void> { |
| 163 | let entries: any[]; |
no test coverage detected