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

Method buildCopybookSection

src/mcp/tools.ts:4436–4466  ·  view source on GitHub ↗

* The COBOL copybooks an explore query named (#2342): where each one's source * lives, and every `COPY` / `EXEC SQL INCLUDE` statement that pulls it in — * locations only, one per line. The source section can afford a few include * windows; this list is what answers "what includes X / what

(copybooks: NamedCopybook[])

Source from the content-addressed store, hash-verified

4434 * says so, so nobody goes hunting for a copybook file that is not here.
4435 */
4436 private buildCopybookSection(copybooks: NamedCopybook[]): string {
4437 const MAX_LISTED_SITES = 25;
4438 const blocks: string[] = [];
4439 for (const copybook of copybooks) {
4440 // Spelled as the code spells it — an include's member, else the file's
4441 // stem — not as the query happened to type it.
4442 const name = copybook.includes[0]?.name
4443 ?? copybook.files[0]?.name.replace(/\.[^.]*$/, '')
4444 ?? copybook.member;
4445 const source = copybook.files.length > 0
4446 ? `source ${copybook.files.map((f) => `\`${f.filePath}\``).join(', ')}`
4447 : 'no indexed source (typically a DB2 DCLGEN member, a compiler-supplied copybook such as SQLCA, or one kept outside this project)';
4448 const count = copybook.includes.length;
4449 if (count === 0) {
4450 blocks.push(`**COBOL copybook \`${name}\`** — ${source}; nothing indexed includes it (no \`COPY\` or \`EXEC SQL INCLUDE\` of it).`, '');
4451 continue;
4452 }
4453 const sites = `${count}${count >= MAX_COPYBOOK_INCLUDES ? '+' : ''} site${count === 1 ? '' : 's'}`;
4454 blocks.push(`**COBOL copybook \`${name}\`** — ${source}; included at ${sites}:`, '');
4455 for (const include of copybook.includes.slice(0, MAX_LISTED_SITES)) {
4456 const statement = /^\s*EXEC\b/i.test(include.signature ?? '') ? 'EXEC SQL INCLUDE' : 'COPY';
4457 blocks.push(`- \`${include.filePath}:${include.startLine}\` — ${statement}`);
4458 }
4459 if (count > MAX_LISTED_SITES) {
4460 const files = new Set(copybook.includes.slice(MAX_LISTED_SITES).map((n) => n.filePath)).size;
4461 blocks.push(`- … +${count - MAX_LISTED_SITES} more site${count - MAX_LISTED_SITES === 1 ? '' : 's'} in ${files} file${files === 1 ? '' : 's'}`);
4462 }
4463 blocks.push('');
4464 }
4465 return blocks.join('\n');
4466 }
4467
4468 /**
4469 * Test-coverage note for a blast-radius entry whose DIRECT callers include no

Callers 1

handleExploreMethod · 0.95

Calls 3

mapMethod · 0.80
pushMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected