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

Function extract

src/resolution/frameworks/tanstack-router.ts:388–438  ·  view source on GitHub ↗
(filePath: string, content: string)

Source from the content-addressed store, hash-verified

386 },
387
388 extract(filePath: string, content: string): FrameworkExtractionResult {
389 // A file-based route file describes ONE route, so the file's own shape says
390 // whether that route is a page. A file holding a code-based route TREE
391 // describes many, and its root component draws the outlet they render into
392 // — judging that file by the same rule would drop every route in it.
393 const layout = isLayoutFile(filePath, content);
394 const entries = parseTanstackRoutes(content).filter((e) => !(e.fileBased && layout));
395 if (entries.length === 0) return { nodes: [], references: [] };
396 const language = languageForFile(filePath);
397 const now = Date.now();
398 const nodes: Node[] = [];
399 const references: UnresolvedRef[] = [];
400 // An index route is the page AT its address; a layout at the same address
401 // wraps it. One address, one screen — the index wins it.
402 const byPath = new Map<string, TanstackRouteEntry>();
403 for (const entry of entries) {
404 const held = byPath.get(entry.path);
405 if (!held || (entry.index && !held.index)) byPath.set(entry.path, entry);
406 }
407 for (const entry of byPath.values()) {
408 const node: Node = {
409 id: routeId(filePath, entry.line, entry.path),
410 kind: 'route',
411 name: entry.path,
412 qualifiedName: `${filePath}::route:${entry.path}`,
413 filePath,
414 startLine: entry.line,
415 endLine: entry.line,
416 startColumn: 0,
417 endColumn: 0,
418 language,
419 updatedAt: now,
420 };
421 nodes.push(node);
422 if (entry.component) {
423 // `calls`, as every component-backed screen binds: a `references`
424 // candidate list is filtered to the ref's own language family.
425 references.push({
426 fromNodeId: node.id,
427 referenceName: entry.component,
428 referenceKind: 'calls',
429 line: entry.line,
430 column: 0,
431 filePath,
432 language,
433 candidates: [entry.component],
434 });
435 }
436 }
437 return { nodes, references };
438 },
439
440 resolve(ref: UnresolvedRef, context: ResolutionContext): ResolvedRef | null {
441 if (ref.referenceKind !== 'calls') return null;

Callers

nothing calls this directly

Calls 7

isLayoutFileFunction · 0.85
parseTanstackRoutesFunction · 0.85
pushMethod · 0.80
languageForFileFunction · 0.70
routeIdFunction · 0.70
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected