MCPcopy
hub / github.com/giancarloerra/SocratiCode / getGraphableFiles

Function getGraphableFiles

src/services/code-graph.ts:598–634  ·  view source on GitHub ↗
(
  projectPath: string,
  extraExts?: Set<string>,
)

Source from the content-addressed store, hash-verified

596 * Includes files with known AST grammars and any extra extensions.
597 */
598export async function getGraphableFiles(
599 projectPath: string,
600 extraExts?: Set<string>,
601): Promise<string[]> {
602 const ig = createIgnoreFilter(projectPath);
603 const extras = extraExts ?? EXTRA_EXTENSIONS;
604 const files: string[] = [];
605
606 async function walk(dir: string): Promise<void> {
607 let entries: import("node:fs").Dirent[];
608 try {
609 entries = await fs.readdir(dir, { withFileTypes: true });
610 } catch {
611 return;
612 }
613
614 for (const entry of entries) {
615 const fullPath = path.join(dir, entry.name);
616 const relPath = toForwardSlash(path.relative(projectPath, fullPath));
617
618 if (shouldIgnore(ig, entry.isDirectory() ? `${relPath}/` : relPath)) continue;
619
620 if (entry.isDirectory()) {
621 await walk(fullPath);
622 } else if (entry.isFile()) {
623 const ext = path.extname(entry.name).toLowerCase();
624 // Include if AST grammar is available OR if it's an extra extension
625 if (getAstGrepLang(ext) !== null || extras.has(ext)) {
626 files.push(relPath);
627 }
628 }
629 }
630 }
631
632 await walk(projectPath);
633 return files;
634}
635
636/**
637 * Build a code graph for a project using ast-grep for polyglot support.

Callers 2

buildCodeGraphFunction · 0.85

Calls 2

createIgnoreFilterFunction · 0.85
walkFunction · 0.70

Tested by

no test coverage detected