Skip to content

Commit 916a392

Browse files
committed
fix: use full type.name refs in TF needs and symbols to prevent over-matching
1 parent ee065bb commit 916a392

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/treemapper/diffctx/parsers/config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717

1818

1919
def _tf_block_symbol(header_line: str) -> str | None:
20+
m = re.match(r'^resource\s+"([^"]+)"\s+"([^"]+)"', header_line)
21+
if m:
22+
return f"{m.group(1)}.{m.group(2)}"
23+
m = re.match(r'^data\s+"([^"]+)"\s+"([^"]+)"', header_line)
24+
if m:
25+
return f"data.{m.group(1)}.{m.group(2)}"
26+
m = re.match(r'^variable\s+"([^"]+)"', header_line)
27+
if m:
28+
return m.group(1)
2029
names = re.findall(r'"([^"]+)"', header_line)
2130
return names[-1] if names else None
2231

src/treemapper/diffctx/utility.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,8 @@ def _collect_terraform_needs(
423423
ref_type, ref_name = m.group(1).lower(), m.group(2).lower()
424424
if ref_type in _TF_SKIP_REF_TYPES:
425425
continue
426-
if len(ref_name) >= 3 and ref_name not in CODE_STOPWORDS:
427-
needs.setdefault(("definition", ref_name), InformationNeed("definition", ref_name, None, 0.9))
426+
full_ref = f"{ref_type}.{ref_name}"
427+
needs.setdefault(("definition", full_ref), InformationNeed("definition", full_ref, None, 0.9))
428428

429429

430430
def needs_from_diff(

0 commit comments

Comments
 (0)