MCPcopy Index your code
hub / github.com/forloopcodes/contextplus / analyzeFile

Function analyzeFile

src/core/parser.ts:328–361  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

326}
327
328export 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
363export function formatSymbol(sym: CodeSymbol, indent: number = 0): string {
364 const prefix = " ".repeat(indent);

Callers 8

parser.test.mjsFile · 0.85
parser.demo.mjsFile · 0.85
semanticNavigateFunction · 0.85
getFileSkeletonFunction · 0.85
buildTreeFunction · 0.85
buildIdentifierIndexFunction · 0.85

Calls 3

parseWithTreeSitterFunction · 0.85
detectLanguageFunction · 0.85
extractHeaderFunction · 0.70

Tested by

no test coverage detected