MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / createContext

Method createContext

src/resolution/index.ts:497–796  ·  view source on GitHub ↗

* Create the resolution context

()

Source from the content-addressed store, hash-verified

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 {

Callers 1

constructorMethod · 0.95

Calls 15

readFileCachedMethod · 0.95
fileContainsMethod · 0.95
nodeByIdMethod · 0.95
resolveViaImportFunction · 0.90
sameLanguageFamilyFunction · 0.90
lexicalPathWithinRootFunction · 0.90
logDebugFunction · 0.90
extractImportMappingsFunction · 0.90
loadProjectAliasesFunction · 0.90
loadGoModuleFunction · 0.90
loadWorkspacePackagesFunction · 0.90
extractReExportsFunction · 0.90

Tested by

no test coverage detected