* 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[])
| 4248 | * says so, so nobody goes hunting for a copybook file that is not here. |
| 4249 | */ |
| 4250 | private buildCopybookSection(copybooks: NamedCopybook[]): string { |
| 4251 | const MAX_LISTED_SITES = 25; |
| 4252 | const blocks: string[] = []; |
| 4253 | for (const copybook of copybooks) { |
| 4254 | // Spelled as the code spells it — an include's member, else the file's |
| 4255 | // stem — not as the query happened to type it. |
| 4256 | const name = copybook.includes[0]?.name |
| 4257 | ?? copybook.files[0]?.name.replace(/\.[^.]*$/, '') |
| 4258 | ?? copybook.member; |
| 4259 | const source = copybook.files.length > 0 |
| 4260 | ? `source ${copybook.files.map((f) => `\`${f.filePath}\``).join(', ')}` |
| 4261 | : 'no indexed source (typically a DB2 DCLGEN member, a compiler-supplied copybook such as SQLCA, or one kept outside this project)'; |
| 4262 | const count = copybook.includes.length; |
| 4263 | if (count === 0) { |
| 4264 | blocks.push(`**COBOL copybook \`${name}\`** — ${source}; nothing indexed includes it (no \`COPY\` or \`EXEC SQL INCLUDE\` of it).`, ''); |
| 4265 | continue; |
| 4266 | } |
| 4267 | const sites = `${count}${count >= MAX_COPYBOOK_INCLUDES ? '+' : ''} site${count === 1 ? '' : 's'}`; |
| 4268 | blocks.push(`**COBOL copybook \`${name}\`** — ${source}; included at ${sites}:`, ''); |
| 4269 | for (const include of copybook.includes.slice(0, MAX_LISTED_SITES)) { |
| 4270 | const statement = /^\s*EXEC\b/i.test(include.signature ?? '') ? 'EXEC SQL INCLUDE' : 'COPY'; |
| 4271 | blocks.push(`- \`${include.filePath}:${include.startLine}\` — ${statement}`); |
| 4272 | } |
| 4273 | if (count > MAX_LISTED_SITES) { |
| 4274 | const files = new Set(copybook.includes.slice(MAX_LISTED_SITES).map((n) => n.filePath)).size; |
| 4275 | blocks.push(`- … +${count - MAX_LISTED_SITES} more site${count - MAX_LISTED_SITES === 1 ? '' : 's'} in ${files} file${files === 1 ? '' : 's'}`); |
| 4276 | } |
| 4277 | blocks.push(''); |
| 4278 | } |
| 4279 | return blocks.join('\n'); |
| 4280 | } |
| 4281 | |
| 4282 | /** |
| 4283 | * Test-coverage note for a blast-radius entry whose DIRECT callers include no |
no test coverage detected