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

Function pythonReopenScope

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

Source from the content-addressed store, hash-verified

1278 * resolve.
1279 */
1280export function pythonReopenScope(
1281 context: ResolutionContext,
1282 changedFiles: string[]
1283): { targetFiles: string[]; sourceDirs: string[]; moduleLeaves: string[] } {
1284 const index = buildPythonModuleIndex(context);
1285 const roots = [...index.projectRoots, ...index.localRoots.keys()];
1286 const moduleNames = (file: string): string[] => {
1287 const out: string[] = [];
1288 const mod = file.replace(/(?:^|\/)__init__\.py$/, '').replace(/\.py$/, '');
1289 for (const root of roots) {
1290 if (root && !mod.startsWith(`${root}/`)) continue;
1291 const rel = root ? mod.slice(root.length + 1) : mod;
1292 if (rel) out.push(rel.replace(/\//g, '.'));
1293 }
1294 return out;
1295 };
1296 const affected = new Set<string>();
1297 const sourceDirs = new Set<string>();
1298 for (const raw of changedFiles) {
1299 const file = raw.replace(/\\/g, '/');
1300 if (!PYTHON_MODULE_FILE.test(file)) continue;
1301 for (const m of moduleNames(file)) affected.add(m);
1302 if (file === '__init__.py' || file.endsWith('/__init__.py')) sourceDirs.add(parentDir(file));
1303 }
1304 const targetFiles: string[] = [];
1305 for (const file of index.files) {
1306 const hit = moduleNames(file).some((m) => {
1307 for (let i = m.length; i > 0; i = m.lastIndexOf('.', i - 1)) {
1308 if (affected.has(m.slice(0, i))) return true;
1309 }
1310 return false;
1311 });
1312 if (hit) targetFiles.push(file);
1313 }
1314 const moduleLeaves = [...new Set([...affected].map((m) => m.slice(m.lastIndexOf('.') + 1)))];
1315 return { targetFiles, sourceDirs: [...sourceDirs], moduleLeaves };
1316}
1317
1318/**
1319 * 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