(filePath: string)
| 326 | } |
| 327 | |
| 328 | export async function analyzeFile(filePath: string): Promise<FileAnalysis> { |
| 329 | const content = await readFile(filePath, "utf-8"); |
| 330 | const lines = content.split("\n"); |
| 331 | const ext = extname(filePath).toLowerCase(); |
| 332 | |
| 333 | let symbols: CodeSymbol[] | null = null; |
| 334 | try { |
| 335 | symbols = await parseWithTreeSitter(content, ext); |
| 336 | } catch { |
| 337 | symbols = null; |
| 338 | } |
| 339 | |
| 340 | if (!symbols) { |
| 341 | const lang = detectLanguage(filePath); |
| 342 | const parsers: Record<string, (l: string[]) => CodeSymbol[]> = { |
| 343 | typescript: parseTypeScript, |
| 344 | javascript: parseTypeScript, |
| 345 | python: parsePython, |
| 346 | rust: parseRust, |
| 347 | go: parseGo, |
| 348 | java: parseJava, |
| 349 | csharp: parseJava, |
| 350 | kotlin: parseJava, |
| 351 | }; |
| 352 | symbols = (parsers[lang ?? ""] ?? parseGeneric)(lines); |
| 353 | } |
| 354 | |
| 355 | return { |
| 356 | path: filePath, |
| 357 | header: extractHeader(lines), |
| 358 | symbols, |
| 359 | lineCount: lines.length, |
| 360 | }; |
| 361 | } |
| 362 | |
| 363 | export function formatSymbol(sym: CodeSymbol, indent: number = 0): string { |
| 364 | const prefix = " ".repeat(indent); |
no test coverage detected