Skip to content

feat: add HCL/Terraform language support#9

Merged
CSCSoftware merged 2 commits intoCSCSoftware:masterfrom
vnz:feat/hcl-support
Apr 25, 2026
Merged

feat: add HCL/Terraform language support#9
CSCSoftware merged 2 commits intoCSCSoftware:masterfrom
vnz:feat/hcl-support

Conversation

@vnz
Copy link
Copy Markdown
Contributor

@vnz vnz commented Apr 18, 2026

Summary

Adds HCL/Terraform support to AiDex. Indexes .tf, .tfvars, and .hcl files with semantic mapping approved in #7:

  • Blocks (resource, module, variable, output, data, locals, provider, ...) → types with dotted names (e.g. resource.aws_instance.web)
  • Function callsmethods
  • Attributesproperties
  • Identifiers + block labelsitems (searchable via aidex_query)

⚠️ Stacked on #8 — this PR targets master but depends on #8 (tree-sitter 0.21 → 0.25 bump). The HCL grammar requires tree-sitter ^0.25.0. Once #8 merges, this PR's diff will collapse to only the HCL changes.

Key design decisions

Block name composition

HCL blocks have a type keyword plus 0-2 string labels. Composed into dotted names:

  • resource "aws_instance" "web"resource.aws_instance.web
  • variable "region"variable.region
  • localslocals

Label indexing bypasses keyword filter

Block labels are user-chosen identifiers. Terraform-common names like default, root, type, data happen to collide with HCL_KEYWORDS but are meaningful here — so the filter is skipped for the label portion of block names (everything after the block type keyword).

Viewer syntax highlighting

Highlight.js has no HCL language module in the base bundle. .tf files fall back to plaintext rather than emitting an unknown-language class that throws.

Terraform project discovery

Added *.tf (glob) and .terraform.lock.hcl (exact) to PROJECT_MARKERS so global_init --index-unindexed discovers Terraform-only repos.

File watcher deduplication

The viewer's live re-indexing watcher previously used a hardcoded regex for supported extensions (also missing .cxx, .mjs, .cjs, .rake, .pyw from before HCL). Replaced with the parser's isSupported() — now automatically tracks whatever the parser supports.

Validation

Comprehensive test against a real Terraform file with 8 block types (resource, variable, module, output, data, locals, provider, nested filter):

  • ✅ All 8 blocks indexed as types with correct dotted names
  • ✅ Block labels (vpc, ubuntu, aws, aws_ami) searchable as items
  • ✅ Keyword-like labels (default, root, type, data) indexed
  • ✅ Block type keywords (resource, variable) correctly filtered
  • ✅ Function calls (lookup, templatefile) captured as methods
  • ✅ Attribute lines correctly classified as property even when containing function calls
  • ✅ Summary reports HCL/Terraform in languages list
  • .terraform/ directory excluded from indexing and watching

Notable review feedback addressed

Codex review surfaced 8 cross-cutting integration points across 5 rounds:

  1. 5 hard-coded extension maps (init, global-init, summary, global-database, viewer)
  2. Block labels missing from searchable items table
  3. Over-aggressive keyword filtering on user-chosen labels
  4. PROJECT_MARKERS for Terraform discovery
  5. Viewer highlight.js unknown language error
  6. File watcher regex drift
  7. Attribute/function_call line type conflict
  8. .terraform/ working directory not excluded

All resolved. Final Codex review: clean.

Test plan

  • Build passes on Node 22 after chore: bump tree-sitter 0.21→0.25 and all grammar packages #8 merges
  • Index a real Terraform project (e.g., terraform-aws-modules/terraform-aws-vpc)
  • Verify aidex_query term="aws_instance" finds resource declarations
  • Verify aidex_signature shows block types with labels
  • Confirm summary reports HCL/Terraform
  • Confirm .terraform/ is excluded
  • Open the viewer and browse .tf files

🤖 Generated with Claude Code

vnz and others added 2 commits April 16, 2026 13:59
Enables support for newer grammar packages (like tree-sitter-hcl) that
require tree-sitter ^0.25.0. Refactors parser setup to use a centralized
GRAMMAR_MAP record instead of per-language switch blocks.

- tree-sitter: ^0.21.0 → ^0.25.0
- All 10 grammar packages bumped to latest compatible versions
- tree-sitter-c-sharp pinned to ~0.23.1 (0.23.5 is ESM-only, incompatible)
- Added asLang() helper for grammar type bridging (NAPI-safe)
- Added .npmrc with legacy-peer-deps for peer dep resolution
- Added .node-version pinning Node 22 (tree-sitter 0.25 requires compilation,
  not yet compatible with Node 24)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Indexes .tf, .tfvars, and .hcl files using the @tree-sitter-grammars/tree-sitter-hcl
grammar. Blocks become types with dotted names (resource.aws_instance.web),
function calls become methods, attributes become properties.

Semantic mapping approved in discussion CSCSoftware#7.

- NEW: src/parser/languages/hcl.ts with keyword filter and node type sets
- src/parser/extractor.ts: compose block names from block type + labels;
  index labels as items so aidex_query finds declarations; skip block-type
  keyword filter for labels (user-chosen names like "default" or "type");
  keep attribute line type even when attribute contains a function_call
- src/parser/tree-sitter.ts: register HCL with .tf/.tfvars/.hcl extensions
- src/parser/languages/index.ts: register HCL config with propertyNodes
- src/viewer/server.ts: use parser's isSupported() for live re-indexing
  (also fixes pre-existing drift for .cxx/.mjs/.cjs/.rake/.pyw); fall back
  to plaintext highlighting for HCL (highlight.js has no hcl module);
  exclude .terraform/ directory from file watcher
- src/commands/init.ts: add HCL extensions to CODE_EXTENSIONS; exclude
  .terraform/ from indexing
- src/commands/global/global-init.ts: add *.tf and .terraform.lock.hcl
  as project markers for discovery
- src/commands/summary.ts + src/db/global-database.ts: report HCL/Terraform
  in language lists
- README.md, CHANGELOG.md, MCP-API-REFERENCE.md, .claude/CLAUDE.md: update
  language count (11 → 12) and language lists

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vnz vnz marked this pull request as ready for review April 18, 2026 10:02
@CSCSoftware CSCSoftware merged commit 7f177ee into CSCSoftware:master Apr 25, 2026
CSCSoftware added a commit that referenced this pull request Apr 25, 2026
- HCL/Terraform language indexing (#9)
- tree-sitter 0.21 → 0.25 across all 10 grammar packages (#8)
- 12 supported languages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants