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

Function resolveComponent

src/resolution/frameworks/astro.ts:176–196  ·  view source on GitHub ↗

* Resolve an Astro component reference using name-based lookup

(
  name: string,
  fromFile: string,
  context: ResolutionContext
)

Source from the content-addressed store, hash-verified

174 * Resolve an Astro component reference using name-based lookup
175 */
176function resolveComponent(
177 name: string,
178 fromFile: string,
179 context: ResolutionContext
180): string | null {
181 // Look for component nodes by name
182 const candidates = context.getNodesByName(name);
183 const components = candidates.filter((n) => n.kind === 'component');
184
185 if (components.length === 0) return null;
186
187 // Prefer the referencing file's folder, or one below it
188 const sameDir = inReferencingFolder(fromFile, components, (n) => n.filePath);
189 if (sameDir.length > 0) return sameDir[0]!.id;
190
191 // No positional signal: only an UNAMBIGUOUS name may resolve — picking
192 // components[0] would choose an arbitrary same-named component in a
193 // multi-app monorepo (#764). Ambiguity falls through to the name-matcher,
194 // whose proximity scoring decides.
195 return components.length === 1 ? components[0]!.id : null;
196}
197
198/**
199 * Convert a path under src/pages/ to an Astro route path.

Callers 1

resolveFunction · 0.70

Calls 2

inReferencingFolderFunction · 0.90
getNodesByNameMethod · 0.65

Tested by

no test coverage detected