-
Notifications
You must be signed in to change notification settings - Fork 37
Add HCL/Terraform language support #108
Copy link
Copy link
Open
Labels
Description
Summary
codedb currently detects .tf, .tfvars, and .hcl files as unknown, so outline, symbol, and deps return nothing for Terraform/HCL codebases. Additionally, .terraform/ provider cache directories are not in skip_dirs, causing the index to balloon with thousands of cached module files.
Problem
On a real Terraform monorepo:
- 19,487 files indexed (17,000+ from
.terraform/caches) - 18s snapshot time, 8.3MB snapshot
- 0 symbols extracted from
.tffiles (detected asunknown) - Search results polluted by cached provider/module files
Proposed Solution
- Add
.terraformand.terragrunt-cachetoskip_dirsinwatcher.zig - Add
hclto theLanguageenum with detection for.tf,.tfvars,.hclextensions - Implement
parseHclLine()recognising top-level HCL block types:resource "type" "name"→struct_defwith symboltype.namedata "type" "name"→struct_defwith symboldata.type.namemodule "name"→importvariable "name"→variableoutput "name"→constantprovider "name"→importlocals/terraform/moved→ keyword blocks
- Record
source = "..."inside module blocks as imports for the dep graph - Add HCL comment support (
#,//,/* */) toisCommentOrBlank
Results after fix
On the same Terraform monorepo:
- 1,836 files indexed (down from 19,487)
- 93ms snapshot time (down from 18s)
- Full symbol extraction across all HCL block types
- Clean search results with no
.terraform/noise
Files touched
src/watcher.zig— 2 lines (add toskip_dirs)src/explore.zig— ~240 lines (language enum, detection, parser, helpers)src/tests.zig— ~250 lines (11 test cases)
Total: 493 inserted lines.
Tests
All existing tests pass (zig build test exit 0). 11 new tests cover:
- Each HCL block type (resource, data, variable, output, module, provider, locals, terraform)
- Full multi-block file parsing
- Comment skipping
findSymbolintegration.tfvarslanguage detectionisCommentOrBlankfor HCL
Reactions are currently unavailable