MCPcopy
hub / github.com/colbymchenry/codegraph / scanPythonGetattr

Function scanPythonGetattr

src/mcp/dynamic-boundaries.ts:326–370  ·  view source on GitHub ↗
(stripped: string, original: string, fileStartLine: number, out: BoundaryMatch[], seen: Map<string, BoundaryMatch>)

Source from the content-addressed store, hash-verified

324const MAX_GETATTR_ARGS = 300;
325
326function scanPythonGetattr(stripped: string, original: string, fileStartLine: number, out: BoundaryMatch[], seen: Map<string, BoundaryMatch>): void {
327 GETATTR_RE.lastIndex = 0;
328 let m: RegExpExecArray | null;
329 while ((m = GETATTR_RE.exec(stripped)) !== null && out.length < MAX_MATCHES_PER_BODY) {
330 const open = m.index + m[0].length - 1;
331 const close = matchBalancedParen(stripped, open);
332 if (close === -1) continue;
333
334 let form: string | undefined;
335 let label = '';
336 // Immediate call: getattr(...)(
337 const after = stripped.slice(close + 1, close + 8);
338 if (/^\s*\(/.test(after)) {
339 form = 'getattr-call';
340 label = 'getattr dispatch';
341 } else {
342 // Assigned form: look back for `name =` and forward for `name(`.
343 const lineStart = stripped.lastIndexOf('\n', m.index) + 1;
344 const before = stripped.slice(lineStart, m.index);
345 const assign = before.match(/(\w+)\s*=\s*$/);
346 if (assign && new RegExp(`\\b${assign[1]}\\s*\\(`).test(stripped.slice(close + 1))) {
347 form = 'getattr-assign';
348 label = 'getattr dispatch (assigned, called later)';
349 }
350 }
351 if (!form) continue;
352
353 const key = singleStringLiteral(original.slice(open + 1, close));
354 const dedupeKey = `${form}|${key ?? ''}`;
355 const prior = seen.get(dedupeKey);
356 if (prior) {
357 prior.moreSites = (prior.moreSites ?? 0) + 1;
358 continue;
359 }
360 const match: BoundaryMatch = {
361 form,
362 label,
363 snippet: snippetAround(original, m.index),
364 line: fileStartLine + countNewlines(original, m.index),
365 ...(key ? { key } : {}),
366 };
367 seen.set(dedupeKey, match);
368 out.push(match);
369 }
370}
371
372/** Index of the `)` balancing `text[open]`, or -1 (cap: MAX_GETATTR_ARGS chars). */
373function matchBalancedParen(text: string, open: number): number {

Callers 1

scanDynamicDispatchFunction · 0.85

Calls 7

matchBalancedParenFunction · 0.85
singleStringLiteralFunction · 0.85
snippetAroundFunction · 0.85
countNewlinesFunction · 0.85
setMethod · 0.80
execMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected