MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / pythonReopenScope

Function pythonReopenScope

src/resolution/import-resolver.ts:1034–1070  ·  view source on GitHub ↗
(
  context: ResolutionContext,
  changedFiles: string[]
)

Source from the content-addressed store, hash-verified

1032 * resolve.
1033 */
1034export function pythonReopenScope(
1035 context: ResolutionContext,
1036 changedFiles: string[]
1037): { targetFiles: string[]; sourceDirs: string[]; moduleLeaves: string[] } {
1038 const index = buildPythonModuleIndex(context);
1039 const roots = [...index.projectRoots, ...index.localRoots.keys()];
1040 const moduleNames = (file: string): string[] => {
1041 const out: string[] = [];
1042 const mod = file.replace(/(?:^|\/)__init__\.py$/, '').replace(/\.py$/, '');
1043 for (const root of roots) {
1044 if (root && !mod.startsWith(`${root}/`)) continue;
1045 const rel = root ? mod.slice(root.length + 1) : mod;
1046 if (rel) out.push(rel.replace(/\//g, '.'));
1047 }
1048 return out;
1049 };
1050 const affected = new Set<string>();
1051 const sourceDirs = new Set<string>();
1052 for (const raw of changedFiles) {
1053 const file = raw.replace(/\\/g, '/');
1054 if (!PYTHON_MODULE_FILE.test(file)) continue;
1055 for (const m of moduleNames(file)) affected.add(m);
1056 if (file === '__init__.py' || file.endsWith('/__init__.py')) sourceDirs.add(parentDir(file));
1057 }
1058 const targetFiles: string[] = [];
1059 for (const file of index.files) {
1060 const hit = moduleNames(file).some((m) => {
1061 for (let i = m.length; i > 0; i = m.lastIndexOf('.', i - 1)) {
1062 if (affected.has(m.slice(0, i))) return true;
1063 }
1064 return false;
1065 });
1066 if (hit) targetFiles.push(file);
1067 }
1068 const moduleLeaves = [...new Set([...affected].map((m) => m.slice(m.lastIndexOf('.') + 1)))];
1069 return { targetFiles, sourceDirs: [...sourceDirs], moduleLeaves };
1070}
1071
1072/**
1073 * What an edit of these Python files can move through

Callers 1

getPythonReopenScopeMethod · 0.90

Calls 7

buildPythonModuleIndexFunction · 0.85
hasMethod · 0.80
pushMethod · 0.80
mapMethod · 0.80
moduleNamesFunction · 0.70
parentDirFunction · 0.70
addMethod · 0.45

Tested by

no test coverage detected