Skip to content

Commit 568c588

Browse files
committed
fix: add TF semantic edges and compound ref identifiers for terraform_019/020
1 parent 916a392 commit 568c588

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/treemapper/diffctx/edges/config/terraform.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def __init__(self) -> None:
104104
class TerraformEdgeBuilder(EdgeBuilder):
105105
weight = 0.60
106106
reverse_weight_factor = 0.40
107+
category = "semantic"
107108

108109
def discover_related_files(
109110
self,

src/treemapper/diffctx/parsers/config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
# moved, import, check, removed, and any future HCL block types.
1616
_TF_BLOCK_HEADER_RE = re.compile(r'^\w[\w-]*(?:\s+"[^"]*")*\s*\{')
1717

18+
_TF_COMPOUND_REF_RE = re.compile(r"(?<![.\w])(\w+)\.(\w+)\.\w+")
19+
_TF_COMPOUND_REF_SKIP = frozenset({"var", "local", "data", "module", "path", "terraform", "count", "each", "self"})
20+
1821

1922
def _tf_block_symbol(header_line: str) -> str | None:
2023
m = re.match(r'^resource\s+"([^"]+)"\s+"([^"]+)"', header_line)
@@ -43,6 +46,15 @@ def _tf_find_block_end(lines: list[str], start: int) -> int:
4346
return len(lines) - 1
4447

4548

49+
def _extract_compound_tf_refs(content: str) -> frozenset[str]:
50+
refs: set[str] = set()
51+
for m in _TF_COMPOUND_REF_RE.finditer(content):
52+
ref_type = m.group(1).lower()
53+
if ref_type not in _TF_COMPOUND_REF_SKIP:
54+
refs.add(f"{m.group(1).lower()}.{m.group(2).lower()}")
55+
return frozenset(refs)
56+
57+
4658
class TerraformStrategy:
4759
priority = 46
4860

@@ -80,6 +92,9 @@ def fragment(self, path: Path, content: str) -> list[Fragment]:
8092
fragments.append(frag)
8193
frag = create_fragment_from_lines(path, lines, start_i + 1, end_i + 1, "config", "data", symbol_name=sym)
8294
if frag:
95+
compound_refs = _extract_compound_tf_refs(frag.content)
96+
if compound_refs:
97+
frag.identifiers = frag.identifiers | compound_refs
8398
fragments.append(frag)
8499
prev_end = end_i
85100

0 commit comments

Comments
 (0)