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

Function scanPythonGetattr

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

Source from the content-addressed store, hash-verified

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

Callers 1

scanDynamicDispatchFunction · 0.85

Calls 8

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

Tested by

no test coverage detected