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

Function scanDynamicDispatch

src/mcp/dynamic-boundaries.ts:270–314  ·  view source on GitHub ↗
(body: string, language: string, fileStartLine: number)

Source from the content-addressed store, hash-verified

268 * line numbers are absolute file lines.
269 */
270export function scanDynamicDispatch(body: string, language: string, fileStartLine: number): BoundaryMatch[] {
271 const original = body.length > MAX_BODY_CHARS ? body.slice(0, MAX_BODY_CHARS) : body;
272 const lang = commentLang(language);
273 const stripped = blankStringContents(lang ? stripCommentsForRegex(original, lang) : original);
274
275 const out: BoundaryMatch[] = [];
276 const seen = new Map<string, BoundaryMatch>(); // form+key → first match (counts extras)
277
278 if (language === 'python') scanPythonGetattr(stripped, original, fileStartLine, out, seen);
279
280 for (const spec of FORMS) {
281 if (out.length >= MAX_MATCHES_PER_BODY) break;
282 if (spec.langs && !spec.langs.has(language)) continue;
283 spec.re.lastIndex = 0;
284 let m: RegExpExecArray | null;
285 while ((m = spec.re.exec(stripped)) !== null) {
286 let sliceEnd = m.index + m[0].length;
287 if (spec.keyWindow) {
288 const windowEnd = Math.min(original.length, sliceEnd + spec.keyWindow);
289 const nl = original.indexOf('\n', sliceEnd);
290 sliceEnd = nl !== -1 && nl < windowEnd ? nl : windowEnd;
291 }
292 const origSlice = original.slice(m.index, sliceEnd);
293 const derived = spec.keyFrom?.(origSlice);
294 const dedupeKey = `${spec.form}|${derived?.key ?? ''}`;
295 const prior = seen.get(dedupeKey);
296 if (prior) {
297 prior.moreSites = (prior.moreSites ?? 0) + 1;
298 continue;
299 }
300 const line = fileStartLine + countNewlines(original, m.index);
301 const match: BoundaryMatch = {
302 form: spec.form,
303 label: spec.label,
304 snippet: snippetAround(original, m.index),
305 line,
306 ...(derived ?? {}),
307 };
308 seen.set(dedupeKey, match);
309 out.push(match);
310 if (out.length >= MAX_MATCHES_PER_BODY) return out;
311 }
312 }
313 return out;
314}
315
316/**
317 * Python getattr dispatch — handled in code, not the FORMS table, because real

Callers 2

Calls 10

stripCommentsForRegexFunction · 0.90
commentLangFunction · 0.85
blankStringContentsFunction · 0.85
scanPythonGetattrFunction · 0.85
countNewlinesFunction · 0.85
snippetAroundFunction · 0.85
hasMethod · 0.80
execMethod · 0.65
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected