* 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[])
| 4295 | * says so, so nobody goes hunting for a copybook file that is not here. |
| 4296 | */ |
| 4297 | private buildCopybookSection(copybooks: NamedCopybook[]): string { |
| 4298 | const MAX_LISTED_SITES = 25; |
| 4299 | const blocks: string[] = []; |
| 4300 | for (const copybook of copybooks) { |
| 4301 | // Spelled as the code spells it — an include's member, else the file's |
| 4302 | // stem — not as the query happened to type it. |
| 4303 | const name = copybook.includes[0]?.name |
| 4304 | ?? copybook.files[0]?.name.replace(/\.[^.]*$/, '') |
| 4305 | ?? copybook.member; |
| 4306 | const source = copybook.files.length > 0 |
| 4307 | ? `source ${copybook.files.map((f) => `\`${f.filePath}\``).join(', ')}` |
| 4308 | : 'no indexed source (typically a DB2 DCLGEN member, a compiler-supplied copybook such as SQLCA, or one kept outside this project)'; |
| 4309 | const count = copybook.includes.length; |
| 4310 | if (count === 0) { |
| 4311 | blocks.push(`**COBOL copybook \`${name}\`** — ${source}; nothing indexed includes it (no \`COPY\` or \`EXEC SQL INCLUDE\` of it).`, ''); |
| 4312 | continue; |
| 4313 | } |
| 4314 | const sites = `${count}${count >= MAX_COPYBOOK_INCLUDES ? '+' : ''} site${count === 1 ? '' : 's'}`; |
| 4315 | blocks.push(`**COBOL copybook \`${name}\`** — ${source}; included at ${sites}:`, ''); |
| 4316 | for (const include of copybook.includes.slice(0, MAX_LISTED_SITES)) { |
| 4317 | const statement = /^\s*EXEC\b/i.test(include.signature ?? '') ? 'EXEC SQL INCLUDE' : 'COPY'; |
| 4318 | blocks.push(`- \`${include.filePath}:${include.startLine}\` — ${statement}`); |
| 4319 | } |
| 4320 | if (count > MAX_LISTED_SITES) { |
| 4321 | const files = new Set(copybook.includes.slice(MAX_LISTED_SITES).map((n) => n.filePath)).size; |
| 4322 | blocks.push(`- … +${count - MAX_LISTED_SITES} more site${count - MAX_LISTED_SITES === 1 ? '' : 's'} in ${files} file${files === 1 ? '' : 's'}`); |
| 4323 | } |
| 4324 | blocks.push(''); |
| 4325 | } |
| 4326 | return blocks.join('\n'); |
| 4327 | } |
| 4328 | |
| 4329 | /** |
| 4330 | * Test-coverage note for a blast-radius entry whose DIRECT callers include no |
no test coverage detected