Fetch the same fact families for every callable in the file, or no file reading at all.
(
source: ImportsSource,
root: string,
request: FileImportsRequest,
)
| 262 | |
| 263 | /** Fetch the same fact families for every callable in the file, or no file reading at all. */ |
| 264 | async function fileIrsFor( |
| 265 | source: ImportsSource, |
| 266 | root: string, |
| 267 | request: FileImportsRequest, |
| 268 | ): Promise<SemanticIR[] | undefined> { |
| 269 | if (request.source === undefined |
| 270 | || source.resolveSymbolAt === undefined |
| 271 | || source.getFacts === undefined |
| 272 | || source.getSnippet === undefined) { |
| 273 | return undefined; |
| 274 | } |
| 275 | const refs = await Promise.all(callableDeclarationLines(request.source).map(async (line) => { |
| 276 | const answer = await source.resolveSymbolAt!(root, request.filePath, line, request.opts).catch(() => undefined); |
| 277 | return answer?.kind === 'ok' ? answer.symbol : undefined; |
| 278 | })); |
| 279 | // A partial collection would make a negative statement about the file |
| 280 | // unsound. Keep no `fileIrs` rather than silently judging the subset. |
| 281 | if (refs.some((ref) => ref === undefined)) { |
| 282 | return undefined; |
| 283 | } |
| 284 | const unique = [...new Map(refs |
| 285 | .filter((ref): ref is NonNullable<typeof ref> => ref !== undefined) |
| 286 | .map((ref) => [ref.qualifiedName ?? `${ref.name}:${ref.range.start.line}`, ref])).values()]; |
| 287 | const provider = source as ImportsSource & IrFactSource; |
| 288 | const built = await Promise.all(unique.map((ref) => buildIr(provider, root, ref, request.opts).catch(() => undefined))); |
| 289 | if (built.some((entry) => entry === undefined)) { |
| 290 | return undefined; |
| 291 | } |
| 292 | return built.map((entry) => entry!.ir); |
| 293 | } |
| 294 | |
| 295 | /** Was der Aufrufer beisteuert: den Text, falls er ihn hat. */ |
| 296 | export interface FileImportsRequest { |
no test coverage detected