(input: ChecklistInput)
| 217 | * is what makes the ids worth caching against. |
| 218 | */ |
| 219 | export function generateChecklist(input: ChecklistInput): ChecklistItem[] { |
| 220 | const items: ChecklistItem[] = []; |
| 221 | const { root, symbol } = input; |
| 222 | // Where an item goes when it is an obligation about the focused symbol |
| 223 | // rather than about somewhere else, and where the ones that could resolve a |
| 224 | // place of their own fall back to when the engine recorded no file. |
| 225 | const here = symbol; |
| 226 | |
| 227 | // core-logic: one item per distinct callee. The reader cannot claim to know |
| 228 | // what a symbol does without knowing what it delegates to. |
| 229 | const callees = distinctBy(input.calls, call => call.targetQualifiedName ?? call.targetName); |
| 230 | for (const call of callees) { |
| 231 | items.push(item( |
| 232 | 'core-logic', |
| 233 | `Understand the call to ${call.targetName}`, |
| 234 | call.targetQualifiedName, |
| 235 | calleeTarget(root, call) ?? here |
| 236 | )); |
| 237 | } |
| 238 | |
| 239 | // inputs: the types the symbol names. A type reference is a shape the reader |
| 240 | // is assumed to know and usually does not. |
| 241 | for (const type of distinctBy(input.typeRefs, ref => ref.qualifiedName ?? ref.name)) { |
| 242 | items.push(item( |
| 243 | 'inputs', |
| 244 | `Know the shape of ${type.name}`, |
| 245 | type.qualifiedName, |
| 246 | refAt(root, type.file, type.line, type.name, type.qualifiedName) ?? here |
| 247 | )); |
| 248 | } |
| 249 | |
| 250 | // implementations: a construction is a class the reader has not read yet, |
| 251 | // which is a different obligation from following a function call. |
| 252 | const constructed = distinctBy( |
| 253 | input.calls.filter(call => call.strategy === CONSTRUCTION_STRATEGY), |
| 254 | call => call.targetQualifiedName ?? call.targetName |
| 255 | ); |
| 256 | for (const call of constructed) { |
| 257 | items.push(item( |
| 258 | 'implementations', |
| 259 | `Read the class ${call.targetName} being constructed`, |
| 260 | call.targetQualifiedName, |
| 261 | calleeTarget(root, call) ?? here |
| 262 | )); |
| 263 | } |
| 264 | |
| 265 | // callers: who breaks when this changes. Capped, because past a point the |
| 266 | // answer is a risk and not a list. |
| 267 | const callers = distinctBy(input.callers, caller => caller.qualifiedName ?? caller.name) |
| 268 | .slice(0, MAX_CALLER_ITEMS); |
| 269 | for (const caller of callers) { |
| 270 | items.push(item( |
| 271 | 'callers', |
| 272 | `See who calls this: ${caller.name}`, |
| 273 | caller.qualifiedName, |
| 274 | refAt(root, caller.file, caller.line, caller.name, caller.qualifiedName) ?? here |
| 275 | )); |
| 276 | } |
no test coverage detected