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

Function emitModuleWiring

src/extraction/languages/terraform.ts:353–389  ·  view source on GitHub ↗

* Bridge a `module "M" { ... }` block across the module boundary with * `:`-scoped references that only the Terraform framework resolver * understands (a plain qualified name would let the generic matcher bind * them to a same-named symbol in an unrelated module — a wrong edge is * worse than no

(
  moduleName: string,
  block: SyntaxNode,
  body: SyntaxNode,
  ctx: Parameters<NonNullable<LanguageExtractor['visitNode']>>[1],
  fromNodeId: string
)

Source from the content-addressed store, hash-verified

351 * "what depends on modules/vpc's var.cidr" reach the callers.
352 */
353function emitModuleWiring(
354 moduleName: string,
355 block: SyntaxNode,
356 body: SyntaxNode,
357 ctx: Parameters<NonNullable<LanguageExtractor['visitNode']>>[1],
358 fromNodeId: string
359): void {
360 for (const attr of body.namedChildren) {
361 if (!attr || attr.type !== 'attribute') continue;
362 const idNode = attr.namedChildren.find((c) => c?.type === 'identifier');
363 if (!idNode) continue;
364 const attrName = getNodeText(idNode, ctx.source);
365 if (attrName === 'source') {
366 const expr = attr.namedChildren.find((c) => c?.type === 'expression');
367 const lit = expr ? findStringLit(expr) : null;
368 const source = lit ? stringLitValue(lit, ctx.source) : '';
369 if (source.startsWith('./') || source.startsWith('../')) {
370 ctx.addUnresolvedReference({
371 fromNodeId,
372 referenceName: `module.${moduleName}:file`,
373 referenceKind: 'imports',
374 line: block.startPosition.row + 1,
375 column: block.startPosition.column,
376 });
377 }
378 continue;
379 }
380 if (MODULE_META_ARGS.has(attrName)) continue;
381 ctx.addUnresolvedReference({
382 fromNodeId,
383 referenceName: `module.${moduleName}:var.${attrName}`,
384 referenceKind: 'references',
385 line: attr.startPosition.row + 1,
386 column: attr.startPosition.column,
387 });
388 }
389}
390
391/** First string_lit anywhere under an expression (source = "./modules/x"). */
392function findStringLit(expr: SyntaxNode): SyntaxNode | null {

Callers 1

terraform.tsFile · 0.85

Calls 5

getNodeTextFunction · 0.90
findStringLitFunction · 0.85
stringLitValueFunction · 0.85
hasMethod · 0.80

Tested by

no test coverage detected