Skip to content

Add HCL/Terraform language support #108

@kenrick-g

Description

@kenrick-g

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 .tf files (detected as unknown)
  • Search results polluted by cached provider/module files

Proposed Solution

  1. Add .terraform and .terragrunt-cache to skip_dirs in watcher.zig
  2. Add hcl to the Language enum with detection for .tf, .tfvars, .hcl extensions
  3. Implement parseHclLine() recognising top-level HCL block types:
    • resource "type" "name"struct_def with symbol type.name
    • data "type" "name"struct_def with symbol data.type.name
    • module "name"import
    • variable "name"variable
    • output "name"constant
    • provider "name"import
    • locals / terraform / moved → keyword blocks
  4. Record source = "..." inside module blocks as imports for the dep graph
  5. Add HCL comment support (#, //, /* */) to isCommentOrBlank

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 to skip_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
  • findSymbol integration
  • .tfvars language detection
  • isCommentOrBlank for HCL

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions