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

Function resolve

src/resolution/frameworks/angular-router.ts:1066–1114  ·  view source on GitHub ↗
(ref: UnresolvedRef, context: ResolutionContext)

Source from the content-addressed store, hash-verified

1064 },
1065
1066 resolve(ref: UnresolvedRef, context: ResolutionContext): ResolvedRef | null {
1067 const layout = LAYOUT_REF.exec(ref.referenceName);
1068 if (layout) {
1069 if (!ref.fromNodeId.endsWith(':angular')) return null;
1070 const component = routeComponent(layout[1]!, ref.filePath, context);
1071 return component
1072 ? { original: ref, targetNodeId: component.id, confidence: 0.95, resolvedBy: 'framework', metadata: { layout: true } }
1073 : null;
1074 }
1075 const lazy = LAZY_COMPONENT_REF.exec(ref.referenceName);
1076 if (lazy) {
1077 if (!ref.fromNodeId.endsWith(':angular')) return null;
1078 const component = lazyComponent(lazy[1]!, lazy[2] === 'default' ? null : lazy[2]!, ref.filePath, context);
1079 return component ? { original: ref, targetNodeId: component.id, confidence: 0.95, resolvedBy: 'framework' } : null;
1080 }
1081
1082 const nav = NAV_CALL.exec(ref.referenceName);
1083 if (!nav || ref.referenceKind !== 'calls') return null;
1084 const verb = nav[1]!;
1085 const routes = angularRoutesFor(angularRouteTable(context), ref.filePath);
1086 if (!routes || routes.exact.size === 0) return null;
1087 const lines = context.getFileLines?.(ref.filePath) ?? context.readFile(ref.filePath)?.split(/\r?\n/) ?? null;
1088 if (!lines) return null;
1089 const arg = firstArgumentText(lines, ref.line, ref.column, verb);
1090 if (arg === null) return null;
1091 // `navigate(['..', id], { relativeTo: this.route })` goes somewhere relative to here.
1092 const extras = nthArgumentText(lines, ref.line, ref.column, verb, 1);
1093 if (extras && /\brelativeTo\b/.test(extras)) return null;
1094 const owner = context
1095 .getNodesInFile(ref.filePath)
1096 .filter((n) => n.kind === 'class' && n.startLine <= ref.line && n.endLine >= ref.line)
1097 .reduce<Node | null>((inner, n) => (!inner || n.startLine >= inner.startLine ? n : inner), null);
1098 const href = angularDestination(arg, ref.filePath, owner, context, 0, true);
1099 if (!href || !href.path.startsWith('/')) return null;
1100 const targets = destinationsForHref(href, routes);
1101 const target = targets[0];
1102 if (!target) return null;
1103 return {
1104 original: ref,
1105 targetNodeId: target.node.id,
1106 ...(targets.length > 1
1107 ? { alsoTargets: targets.slice(1).map((t) => ({ targetNodeId: t.node.id, metadata: { href: t.href.display, navMethod: verb } })) }
1108 : {}),
1109 confidence: 0.95,
1110 resolvedBy: 'framework',
1111 edgeKind: 'navigates',
1112 metadata: { href: target.href.display, navMethod: verb },
1113 };
1114 },
1115};
1116
1117/** For the template synthesizer: a template file's path, from the component file that names it. */

Callers

nothing calls this directly

Calls 13

firstArgumentTextFunction · 0.90
nthArgumentTextFunction · 0.90
destinationsForHrefFunction · 0.90
lazyComponentFunction · 0.85
angularRoutesForFunction · 0.85
angularRouteTableFunction · 0.85
angularDestinationFunction · 0.85
getFileLinesMethod · 0.80
mapMethod · 0.80
routeComponentFunction · 0.70
execMethod · 0.65
readFileMethod · 0.65

Tested by

no test coverage detected