feat: Add HCL/Terraform language support#109
feat: Add HCL/Terraform language support#109kenrick-g wants to merge 2 commits intojustrach:mainfrom
Conversation
- Add `hcl` to Language enum with detection for .tf, .tfvars, .hcl extensions - Implement parseHclLine() recognising 7 top-level block types: resource, data, module, variable, output, provider, locals/terraform/moved - Record module `source = "..."` as imports for dependency graph - Add HCL comment support (#, //, /* */) to isCommentOrBlank - Add .terraform and .terragrunt-cache to skip_dirs in watcher.zig - Add 11 test cases covering all block types, comments, findSymbol, and language detection Tested on a ~20K-file Terraform monorepo: file count dropped from 19,487 to 1,836, snapshot time from 18s to 93ms, and symbol extraction works across all HCL block types.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6e2ff44035
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
…blocks Addresses review feedback: 1. Track /* ... */ block comment state across lines so commented-out resource/variable blocks are not indexed as live symbols. 2. Only extract `source = "..."` as an import when inside a module block (tracked via brace depth), preventing false dep graph edges from provisioner/file source attributes. Adds 2 test cases covering both fixes.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 87728695ee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (std.mem.indexOf(u8, line, "{") != null) { | ||
| in_module.* = true; | ||
| brace_depth.* = 1; |
There was a problem hiding this comment.
Enter module context when block brace is on next line
in_module is only enabled when the module declaration line already contains {, so valid Terraform formatted as module "x" on one line and { on the next never enters module-tracking mode. In that case, subsequent source = "..." inside the module is not captured in outline.imports, which makes dependency graph results incomplete for a supported HCL style.
Useful? React with 👍 / 👎.
| for (line) |ch| { | ||
| if (ch == '{') brace_depth.* += 1; | ||
| if (ch == '}') brace_depth.* -= 1; |
There was a problem hiding this comment.
Ignore braces inside strings when tracking module depth
Module depth is updated by counting every { and } character in the raw line, including braces inside quoted values, so a line like description = "}" can prematurely close module context (or "{" can keep it open). This causes source extraction to be missed inside real modules or to leak into following non-module blocks, producing incorrect dependency edges.
Useful? React with 👍 / 👎.
|
Pushed fixes addressing all Codex findings:
Both fixes have passing tests. The P1 (block comments) and original P2 (source scoping) were already fixed in the previous commit. @codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 87728695ee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (std.mem.indexOf(u8, line, "{") != null) { | ||
| in_module.* = true; | ||
| brace_depth.* = 1; |
There was a problem hiding this comment.
Enter module scope when opening brace is on next line
Set in_module when a module "..." block starts even if { is placed on the following line. As written, module context is only enabled when { is on the same line, so common formatting like module "x" then newline { causes all nested source = "..." values to be skipped, leaving dependency imports incomplete.
Useful? React with 👍 / 👎.
| for (line) |ch| { | ||
| if (ch == '{') brace_depth.* += 1; | ||
| if (ch == '}') brace_depth.* -= 1; |
There was a problem hiding this comment.
Ignore quoted braces when updating module brace depth
The module brace counter currently increments/decrements on every {/} byte, including braces inside string literals. In module blocks, values like description = "}" can prematurely drop brace_depth to zero and exit module scope, so a later source = "..." is missed (or scope may drift and capture non-module source lines). Brace tracking needs to skip quoted content.
Useful? React with 👍 / 👎.
|
Hey @kenrick-g, Codex flagged 4 issues (you can see them in the review comments above). The good news is your second commit already fixes 2 of them (P1 block comments + P2 source scoping). Two remain: P2: Module
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 87728695ee
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (std.mem.indexOf(u8, line, "{") != null) { | ||
| in_module.* = true; | ||
| brace_depth.* = 1; | ||
| } |
There was a problem hiding this comment.
Enter module scope even when
{ is on next line
The parser only sets in_module when the module declaration line already contains {, so formatted Terraform like module "vpc" followed by { on the next line never enters module scope. In that case source = "..." inside the module is skipped, so dependency imports are silently missing for a common HCL style.
Useful? React with 👍 / 👎.
| for (line) |ch| { | ||
| if (ch == '{') brace_depth.* += 1; | ||
| if (ch == '}') brace_depth.* -= 1; |
There was a problem hiding this comment.
Ignore braces inside strings when tracking module depth
Brace depth is updated by scanning raw characters, which counts {/} inside quoted values (for example description = "}"). That can prematurely drop brace_depth to 0 and exit module scope before the real closing brace, causing later source = "..." lines in the same module to be missed.
Useful? React with 👍 / 👎.
Closes #108
Summary
hcltoLanguageenum with detection for.tf,.tfvars,.hclextensionsparseHclLine()recognising 7 top-level block types:resource,data,module,variable,output,provider,locals/terraform/movedsource = "..."as imports for dependency graph#,//,/* */) toisCommentOrBlank.terraformand.terragrunt-cachetoskip_dirsinwatcher.zigFiles touched
src/watcher.zig.terraform,.terragrunt-cachetoskip_dirssrc/explore.zigparseHclLine(), helperssrc/tests.zigTests run
Before (on a ~20K-file Terraform monorepo)
.terraform/caches).tffiles detected asunknown, 0 symbols extractedoutline,symbol,depsreturn nothing for Terraform filesAfter
.terraform/excluded)resource,data,variable,output,module,provider,locals,terraformfind azurerm_kubernetes_cluster.main→ exact match atcluster.tf:60Nearby non-regression
Existing Python, TypeScript, Rust, and Zig parser tests all pass unchanged. No modifications to existing parser logic.
Branch
Rebased onto current
main. No generated files, no lockfile changes.Confirmation
This submission matches
CONTRIBUTING.md.