feat: add HCL/Terraform language support#9
Merged
CSCSoftware merged 2 commits intoCSCSoftware:masterfrom Apr 25, 2026
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds HCL/Terraform support to AiDex. Indexes
.tf,.tfvars, and.hclfiles with semantic mapping approved in #7:resource,module,variable,output,data,locals,provider, ...) → types with dotted names (e.g.resource.aws_instance.web)aidex_query)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.webvariable "region"→variable.regionlocals→localsLabel indexing bypasses keyword filter
Block labels are user-chosen identifiers. Terraform-common names like
default,root,type,datahappen 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.
.tffiles fall back toplaintextrather than emitting an unknown-language class that throws.Terraform project discovery
Added
*.tf(glob) and.terraform.lock.hcl(exact) toPROJECT_MARKERSsoglobal_init --index-unindexeddiscovers 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,.pywfrom before HCL). Replaced with the parser'sisSupported()— 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):
vpc,ubuntu,aws,aws_ami) searchable as itemsdefault,root,type,data) indexedresource,variable) correctly filteredlookup,templatefile) captured as methodspropertyeven when containing function callsHCL/Terraformin languages list.terraform/directory excluded from indexing and watchingNotable review feedback addressed
Codex review surfaced 8 cross-cutting integration points across 5 rounds:
.terraform/working directory not excludedAll resolved. Final Codex review: clean.
Test plan
aidex_query term="aws_instance"finds resource declarationsaidex_signatureshows block types with labels.terraform/is excluded.tffiles🤖 Generated with Claude Code