A provider slice over one invented graph, with its calls written down.
(graph: Record<string, CallSite[]>)
| 104 | |
| 105 | /** A provider slice over one invented graph, with its calls written down. */ |
| 106 | function sourceOver(graph: Record<string, CallSite[]>): Recorder { |
| 107 | const factCalls: string[] = []; |
| 108 | const resolveCalls: string[] = []; |
| 109 | const unresolvable = new Set<string>(); |
| 110 | return { |
| 111 | factCalls, |
| 112 | resolveCalls, |
| 113 | unresolvable, |
| 114 | async getFacts( |
| 115 | _root: string, |
| 116 | symbol: SymbolRef, |
| 117 | kinds: string[], |
| 118 | _opts?: ProviderQueryOptions, |
| 119 | ): Promise<SymbolFacts> { |
| 120 | expect(kinds).toEqual(['callees']); |
| 121 | factCalls.push(symbol.qualifiedName ?? symbol.name); |
| 122 | const short = (symbol.qualifiedName ?? '').slice(PROJECT.length + 1); |
| 123 | return { |
| 124 | callees: { value: graph[short] ?? [], state: 'known', evidence: [] }, |
| 125 | }; |
| 126 | }, |
| 127 | async resolveSymbolAt( |
| 128 | _root: string, |
| 129 | filePath: string, |
| 130 | line: number, |
| 131 | _opts?: ProviderQueryOptions, |
| 132 | ): Promise<ResolveResult> { |
| 133 | resolveCalls.push(`${filePath}:${line}`); |
| 134 | if (unresolvable.has(filePath)) { |
| 135 | return { kind: 'file-not-indexed', filePath }; |
| 136 | } |
| 137 | const name = Object.keys(DECLARED).find( |
| 138 | (key) => DECLARED[key].file === filePath && DECLARED[key].line === line, |
| 139 | ); |
| 140 | if (name === undefined) { |
| 141 | return { kind: 'no-symbol-at-line', filePath }; |
| 142 | } |
| 143 | return { kind: 'ok', symbol: symbolNamed(name), enclosing: [] }; |
| 144 | }, |
| 145 | }; |
| 146 | } |
| 147 | |
| 148 | const shortNames = (closure: { nodes: { symbol: SymbolRef }[] }): string[] => |
| 149 | closure.nodes.map((node) => node.symbol.name); |