* Create the resolution context
()
| 495 | * Create the resolution context |
| 496 | */ |
| 497 | private createContext(): ResolutionContext { |
| 498 | return { |
| 499 | resolveImport: (ref) => resolveViaImport(ref, this.context), |
| 500 | getNodesInFile: (filePath: string) => { |
| 501 | if (!this.nodeCache.has(filePath)) { |
| 502 | this.nodeCache.set(filePath, this.queries.getNodesByFile(filePath)); |
| 503 | } |
| 504 | return this.nodeCache.get(filePath)!; |
| 505 | }, |
| 506 | |
| 507 | fileHasExportedNode: (filePath: string) => { |
| 508 | const cached = this.nodeCache.get(filePath); |
| 509 | return cached !== undefined ? cached.some((n) => n.isExported) : this.queries.fileHasExportedNode(filePath); |
| 510 | }, |
| 511 | |
| 512 | getExportedNodesInFile: (filePath: string) => { |
| 513 | const cached = this.nodeCache.get(filePath); |
| 514 | return cached !== undefined ? cached.filter((n) => n.isExported) : this.queries.getExportedNodesByFile(filePath); |
| 515 | }, |
| 516 | |
| 517 | getNodesInFileNamed: (filePath: string, name: string) => { |
| 518 | const cached = this.nodeCache.get(filePath); |
| 519 | return cached !== undefined ? cached.filter((n) => n.name === name) : this.queries.getNodesByFileAndName(filePath, name); |
| 520 | }, |
| 521 | |
| 522 | getNodesByName: (name: string) => { |
| 523 | const cached = this.nameCache.get(name); |
| 524 | if (cached !== undefined) return cached; |
| 525 | const result = this.queries.getNodesByName(name); |
| 526 | this.nameCache.set(name, result); |
| 527 | return result; |
| 528 | }, |
| 529 | |
| 530 | getMethodMatches: (typeName: string, methodName: string, language: Language) => { |
| 531 | const key = `${language} ${typeName}::${methodName}`; |
| 532 | const cached = this.methodMatchCache.get(key); |
| 533 | if (cached !== undefined) return cached; |
| 534 | let candidates = this.nameCache.get(methodName); |
| 535 | if (candidates === undefined) { |
| 536 | candidates = this.queries.getNodesByName(methodName); |
| 537 | this.nameCache.set(methodName, candidates); |
| 538 | } |
| 539 | const want = `${typeName}::${methodName}`; |
| 540 | let matches: Node[]; |
| 541 | if (typeName.includes('::') || methodName.includes(':')) { |
| 542 | // Legacy linear filter for the shapes the owner index below can't |
| 543 | // key exactly: a multi-segment typeName (the endsWith test then |
| 544 | // spans more than two `::` segments) and ObjC selectors (whose |
| 545 | // single/empty-keyword colons defeat the segment split). Tiny |
| 546 | // populations; the per-key memo above still amortizes them. |
| 547 | matches = []; |
| 548 | for (const m of candidates) { |
| 549 | if (m.kind !== 'method') continue; |
| 550 | if (!sameLanguageFamily(m.language, language)) continue; |
| 551 | const qn = m.qualifiedName; |
| 552 | if (qn === want || qn.endsWith(`::${want}`)) matches.push(m); |
| 553 | } |
| 554 | } else { |
no test coverage detected