Skip to content

feat(zig): add Zig 0.16+ language support#1

Open
guysenpai wants to merge 3 commits into
mainfrom
claude/add-mcp-server-Xpl3m
Open

feat(zig): add Zig 0.16+ language support#1
guysenpai wants to merge 3 commits into
mainfrom
claude/add-mcp-server-Xpl3m

Conversation

@guysenpai
Copy link
Copy Markdown
Collaborator

Summary

  • Adds Zig language support (Zig 0.16+) via tree-sitter-zig, indexing .zig and .zon files
  • Extracts: top-level functions, struct declarations + methods, enums + members, error sets (as enums), @import (as import nodes with unresolved imports references), pub visibility, plain constants/variables, and test "..." { ... } blocks (as functions)
  • Adds **/*.zig and **/*.zon to DEFAULT_CONFIG.include so the scanner picks them up out of the box

Implementation notes

  • New extractor: src/extraction/languages/zig.ts (modelled after rust.ts)
  • Registered in src/extraction/languages/index.ts
  • zig added to LANGUAGES const in src/types.ts
  • WASM grammar wired via tree-sitter-wasms package (no local wasm file needed)
  • Struct methods are classified automatically via the existing isInsideClassLikeNode() scope-stack mechanism in tree-sitter.ts — no changes to core extractors
  • Zig's parameters AST node has no field name, so getSignature finds it by type instead of getChildByField
  • pub is an anonymous token in the tree-sitter-zig grammar — detected by iterating children

Known limitation (documented in code + CHANGELOG)

Comptime-generated types like fn Physics(comptime R: type) type { return struct { ... }; } are not resolvable at the tree-sitter level (would require full type inference). Methods on such types are not extracted.

Test plan

  • 12 new tests in __tests__/extraction.test.ts under describe('Zig Extraction', ...) covering: function declarations (pub/private), signatures, structs + fields, struct methods + containment, enums + members, error sets, @import (simple + chained), constants/variables, test blocks, function calls
  • npm run test → 531/531 pass (with GIT_CONFIG_KEY_0=commit.gpgsign GIT_CONFIG_VALUE_0=false to bypass the unrelated test-env GPG signing failures)
  • npm run build → clean
  • Indexed real Zig fixtures: ≥10 fn/struct/enum nodes + ≥1 calls edge between Zig nodes

Generated by Claude Code

claude added 3 commits May 16, 2026 19:42
Tree-sitter-zig WASM from tree-sitter-wasms, no native build required.

Extracts: top-level functions, structs with fields/methods, enums,
error sets (as enums), @import statements, test declarations, and
function calls. Pub/private visibility is detected from the anonymous
`pub` token.

Known limitation: comptime-generated types (e.g. `fn Foo(comptime T:
type) type { return struct {...}; }`) are not extractable at the AST
level and are documented in zig.ts.

https://claude.ai/code/session_017AQjdPam3enwct9vFi4G1S
Adds **/*.zig and **/*.zon to DEFAULT_CONFIG.include so the CLI
picks up Zig sources without manual config. Documents the new
language support and the comptime-type limitation in CHANGELOG.

https://claude.ai/code/session_017AQjdPam3enwct9vFi4G1S
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