Skip to content

feat: Add Zig language support#279

Merged
unhappychoice merged 7 commits intomainfrom
feature/add-zig-language-support
Oct 5, 2025
Merged

feat: Add Zig language support#279
unhappychoice merged 7 commits intomainfrom
feature/add-zig-language-support

Conversation

@unhappychoice
Copy link
Copy Markdown
Owner

@unhappychoice unhappychoice commented Oct 5, 2025

close: #275

Summary

  • Add complete Zig programming language support
  • Implement tree-sitter parser for Zig code extraction
  • Add integration tests and documentation

Changes

  • Language Definition: Add Zig language struct with .zig extension support
  • Parser: Implement ZigExtractor with query patterns for functions, structs, enums, and unions
  • Color Scheme: Add Zig colors to all themes (dark, light, ascii)
  • Tests: Add comprehensive integration tests with snapshots
  • Documentation: Update README, CONTRIBUTING, and language docs
  • CLI: Add Zig to help messages and supported languages list

Test plan

  • All existing tests pass (636 passed)
  • New Zig integration tests pass (3/3)
  • Clippy passes with no warnings
  • Code formatted with cargo fmt

Acceptance Criteria (from #275)

  • Zig files (.zig) are recognized and parsed correctly
  • Functions and structs are extracted as typing challenges
  • Comment ranges are properly identified
  • Tests pass for Zig language support

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added Zig language support, including recognition of functions, structs, enums, and unions.
    • Integrated Zig into parsing and extraction workflows with dedicated theming/colors across light and dark modes.
    • Zig now appears in language selections and filtering in the UI/CLI.
  • Documentation

    • Updated README and usage guidelines to list Zig among supported languages.
    • Expanded supported-languages documentation with Zig details and extraction capabilities.
    • Updated CLI help text to include Zig in language options.

unhappychoice and others added 7 commits October 6, 2025 01:13
Add tree-sitter-zig v1.0 for Zig language support

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add Zig language struct with .zig extension support
- Register Zig in all_languages() list
- Implement comment node validation for Zig

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Implement ZigExtractor with query patterns for functions, structs, enums, and unions
- Add support for extracting code blocks (loops, conditionals, etc.)
- Register Zig parser in ParserRegistry

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add Zig colors to dark, light, and ascii themes
- Add lang_zig field to ColorScheme struct
- Implement Colors::lang_zig() method

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add test cases for function, struct, and mixed code extraction
- Add snapshot tests for validation
- Register Zig in test helper functions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add Zig to --langs option help text
- Add Zig to trending command supported languages

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add Zig to README features list
- Add Zig language details to supported-languages.md
- Add Zig to usage.md trending languages
- Update CONTRIBUTING.md with current architecture for adding languages

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 5, 2025

Walkthrough

Adds Zig language support across the codebase: language model and registration, tree-sitter dependency and Zig extractor/parser, color scheme entries and accessor, CLI/help and docs updates, and integration tests. Assets updated for Zig colors. Test harness extended to recognize Zig.

Changes

Cohort / File(s) Summary
Dependency
Cargo.toml
Adds dependency: tree-sitter-zig = "1.0".
Language model & registration
src/domain/models/languages/zig.rs, src/domain/models/languages/mod.rs, src/domain/models/language.rs
Introduces Zig type implementing Language; exports module/re-export; includes Zig in all_languages().
Parser & registry
src/domain/services/source_code_parser/parsers/zig.rs, src/domain/services/source_code_parser/parsers/mod.rs
Adds ZigExtractor with tree-sitter patterns and parser factory; registers Zig in parser registry.
Colors & assets
src/domain/models/color_scheme.rs, src/presentation/ui/colors.rs, assets/languages/lang_*.json
Adds lang_zig field, accessor Colors::lang_zig(), and theme entries: ASCII "yellow", dark RGB (249,169,60), light RGB (189,99,0).
Docs & CLI help
README.md, docs/supported-languages.md, docs/usage.md, src/presentation/cli/args.rs
Documents Zig in features/supported lists; updates CLI long_help to include Zig.
Tests
tests/integration/languages/mod.rs, tests/integration/languages/zig/mod.rs, tests/integration/languages/zig/extractor.rs, tests/integration/mod.rs
Adds Zig integration tests (functions/structs/mixed), exposes zig test modules, and maps "zig" to Zig in test language resolver.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant CLI as CLI
  participant PR as ParserRegistry
  participant ZE as ZigExtractor
  participant TS as tree-sitter-zig
  participant CH as Chunker

  CLI->>PR: request parser for "zig"
  PR-->>CLI: Zig parser factory
  CLI->>ZE: create_parser()
  ZE->>TS: set_language(zig)
  TS-->>ZE: language set (ok/error)
  ZE-->>CLI: Parser (or error)

  CLI->>ZE: parse(source.zig)
  ZE->>TS: parse + run queries (decls/comments)
  TS-->>ZE: AST + captures
  ZE->>CH: map captures to ChunkType
  CH-->>CLI: chunks (functions/structs/enums/unions, blocks)
  Note over CLI,ZE: Error paths return ExtractionFailed on setup/parse failure
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

I hop through code with zig and zest,
New parser burrows, passing tests. 🐇⚡
Colors glow—amber bright,
Chunks pop out in tidy sight.
With tree-sitter roots held snug,
I nibble bytes and whisper: “Zig!”

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The docs/CONTRIBUTING.md file changes introduce a complete “NewLang” integration example and code definitions that are unrelated to adding Zig support and exceed the scope of the linked issue objectives. The changes to docs/CONTRIBUTING.md should be revised to only update guidelines relevant to Zig support or removed if they pertain to a different language integration.
Docstring Coverage ⚠️ Warning Docstring coverage is 4.76% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly and concisely summarizes the primary change of adding Zig language support, which matches the main modifications in the changeset without unnecessary detail or noise.
Linked Issues Check ✅ Passed The pull request implements all coding requirements from linked issue #275 by adding the Zig language definition, integrating a Tree-sitter parser with query patterns for functions, structs, enums, and unions, correctly identifying comments, and including passing integration tests for Zig extraction.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/add-zig-language-support

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Oct 5, 2025

Codecov Report

❌ Patch coverage is 53.84615% with 42 lines in your changes missing coverage. Please review.
✅ Project coverage is 24.71%. Comparing base (65895b6) to head (3009e8b).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
.../domain/services/source_code_parser/parsers/zig.rs 56.06% 29 Missing ⚠️
src/domain/models/languages/zig.rs 37.50% 10 Missing ⚠️
src/presentation/ui/colors.rs 0.00% 3 Missing ⚠️

❌ Your patch status has failed because the patch coverage (53.84%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.
❌ Your project status has failed because the head coverage (24.71%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #279      +/-   ##
==========================================
+ Coverage   24.59%   24.71%   +0.12%     
==========================================
  Files         195      197       +2     
  Lines       21743    21834      +91     
==========================================
+ Hits         5347     5396      +49     
- Misses      16396    16438      +42     
Files with missing lines Coverage Δ
src/domain/models/color_scheme.rs 92.43% <100.00%> (+0.12%) ⬆️
src/domain/models/language.rs 82.07% <100.00%> (+0.17%) ⬆️
.../domain/services/source_code_parser/parsers/mod.rs 77.14% <100.00%> (+0.21%) ⬆️
src/presentation/ui/colors.rs 18.13% <0.00%> (-0.31%) ⬇️
src/domain/models/languages/zig.rs 37.50% <37.50%> (ø)
.../domain/services/source_code_parser/parsers/zig.rs 56.06% <56.06%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
Cargo.toml (1)

49-49: Update tree-sitter-zig dependency to 1.1.2
The tree-sitter-zig crate is currently pinned at "1.0", but the latest stable release is "1.1.2". Please bump the version in Cargo.toml.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65895b6 and 3009e8b.

⛔ Files ignored due to path filters (4)
  • Cargo.lock is excluded by !**/*.lock
  • tests/integration/languages/snapshots/r#mod__integration__languages__extractor__test_zig_function_extraction.snap is excluded by !**/*.snap
  • tests/integration/languages/snapshots/r#mod__integration__languages__extractor__test_zig_mixed_extraction.snap is excluded by !**/*.snap
  • tests/integration/languages/snapshots/r#mod__integration__languages__extractor__test_zig_struct_extraction.snap is excluded by !**/*.snap
📒 Files selected for processing (20)
  • Cargo.toml (1 hunks)
  • README.md (1 hunks)
  • assets/languages/lang_ascii.json (1 hunks)
  • assets/languages/lang_dark.json (1 hunks)
  • assets/languages/lang_light.json (1 hunks)
  • docs/CONTRIBUTING.md (1 hunks)
  • docs/supported-languages.md (3 hunks)
  • docs/usage.md (1 hunks)
  • src/domain/models/color_scheme.rs (2 hunks)
  • src/domain/models/language.rs (2 hunks)
  • src/domain/models/languages/mod.rs (2 hunks)
  • src/domain/models/languages/zig.rs (1 hunks)
  • src/domain/services/source_code_parser/parsers/mod.rs (3 hunks)
  • src/domain/services/source_code_parser/parsers/zig.rs (1 hunks)
  • src/presentation/cli/args.rs (2 hunks)
  • src/presentation/ui/colors.rs (1 hunks)
  • tests/integration/languages/mod.rs (1 hunks)
  • tests/integration/languages/zig/extractor.rs (1 hunks)
  • tests/integration/languages/zig/mod.rs (1 hunks)
  • tests/integration/mod.rs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/domain/models/languages/zig.rs (2)
src/domain/models/language.rs (6)
  • hash (155-157)
  • name (11-11)
  • extensions (19-19)
  • color (40-42)
  • display_name (14-16)
  • is_valid_comment_node (45-45)
src/presentation/ui/colors.rs (1)
  • lang_zig (156-158)
src/domain/services/source_code_parser/parsers/zig.rs (1)
src/domain/services/source_code_parser/parsers/mod.rs (9)
  • tree_sitter_language (32-32)
  • query_patterns (36-36)
  • comment_query (34-34)
  • capture_name_to_chunk_type (37-37)
  • extract_name (38-38)
  • middle_implementation_query (40-40)
  • middle_capture_name_to_chunk_type (41-41)
  • create_parser (101-108)
  • new (53-89)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Coverage
🔇 Additional comments (26)
docs/usage.md (1)

124-124: Documentation update looks good.

Zig is correctly added to the supported languages list with proper capitalization and formatting, consistent with the existing entries.

docs/supported-languages.md (3)

23-23: Language table entry is well-formatted.

The Zig entry follows the established pattern with correct extension (.zig) and tree-sitter grammar reference (tree_sitter_zig).


161-165: Extraction features are clearly documented.

The documented Zig extraction features (functions, structs, enums, unions) are well-described with their corresponding tree-sitter node types, consistent with documentation patterns for other languages.


183-183: Configuration example is updated correctly.

Zig is appropriately added to the default language filter list.

src/presentation/cli/args.rs (2)

45-45: CLI help text updated correctly.

The addition of "zig" to the supported languages list maintains the correct lowercase format and follows the established pattern.


84-84: Trending command help updated properly.

"Zig" is correctly added in title case, consistent with how other language names are displayed in the trending command's help text.

docs/CONTRIBUTING.md (1)

296-442: Excellent documentation for language support.

The updated guide for adding language support is comprehensive and well-structured. It provides:

  • Clear step-by-step instructions with code examples
  • Consistent placeholder naming (newlang/NewLang)
  • All necessary integration points (dependency, extractor, tests, docs, colors)
  • Query writing guidelines

This will significantly help contributors add new language support.

tests/integration/languages/mod.rs (1)

18-18: Test module registration is correct.

The zig module is properly declared and placed in alphabetical order after typescript.

assets/languages/lang_ascii.json (1)

18-18: ASCII color mapping added correctly.

The lang_zig entry is properly formatted and uses "yellow", which is consistent with other languages like Rust and Python in this theme.

assets/languages/lang_dark.json (1)

18-18: Dark theme color added successfully.

The Zig color entry uses RGB values (249, 169, 60), creating a distinctive orange/amber color that's visually appropriate and consistent with the dark theme's color palette.

assets/languages/lang_light.json (1)

18-18: LGTM!

The Zig color entry follows the same pattern as other language colors and is correctly positioned in the JSON structure.

README.md (1)

15-15: LGTM!

Zig is correctly added to the supported languages list in the README, maintaining consistency with the existing documentation style.

tests/integration/mod.rs (1)

69-69: LGTM!

The Zig mapping in the test helper follows the established pattern and is correctly positioned alphabetically.

tests/integration/languages/zig/mod.rs (1)

1-1: LGTM!

The module declaration follows the standard pattern used for other language test modules.

src/presentation/ui/colors.rs (1)

156-158: LGTM!

The lang_zig() accessor follows the same pattern as other language color methods, maintaining consistency across the public API.

src/domain/models/languages/mod.rs (2)

17-17: LGTM!

The Zig module declaration follows the established pattern and is correctly positioned alphabetically.


35-35: LGTM!

The Zig re-export is consistent with other language re-exports and properly positioned.

src/domain/models/language.rs (2)

3-3: LGTM!

Zig is correctly added to the imports, maintaining consistency with the existing import pattern.


75-75: LGTM!

Zig is properly added to the all_languages() catalog, making it available throughout the application.

src/domain/models/color_scheme.rs (2)

149-149: LGTM!

The lang_zig field is correctly added to the ColorScheme struct, following the same pattern as other language color fields.


324-327: LGTM!

The Zig color initialization follows the established pattern, with appropriate fallback to yellow and consistent HashMap lookup.

src/domain/services/source_code_parser/parsers/mod.rs (3)

3-3: LGTM!

Zig is correctly added to the language imports alongside other supported languages.


29-29: LGTM!

The Zig module is properly declared and exposed publicly, consistent with other language modules.


86-86: LGTM!

Zig is correctly registered using the register_language! macro, following the same pattern as all other supported languages.

src/domain/models/languages/zig.rs (1)

1-28: LGTM!

The Zig language model implementation is clean and correct:

  • Properly implements all required Language trait methods
  • Uses appropriate derives for the type
  • Comment node validation is correctly implemented
  • Follows the same pattern as other language implementations in the codebase
src/domain/services/source_code_parser/parsers/zig.rs (1)

1-89: LGTM!

The ZigExtractor implementation is well-structured and follows the established patterns from other language extractors:

  • Tree-sitter query patterns correctly capture Zig functions, structs, enums, and unions
  • Comment extraction is properly configured
  • Chunk type mappings are appropriate
  • Middle-level construct extraction (loops, conditionals, blocks) is comprehensive
  • Name extraction logic correctly walks the AST to find identifiers
  • Parser factory includes proper error handling

The implementation should correctly extract typing challenges from Zig source files.

Comment on lines +38 to +42
total_chunks: 3,
chunk_counts: {
File: 1,
Function: 0,
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Incomplete chunk_counts specification.

The total_chunks expects 3, but chunk_counts only accounts for File:1 + Function:0 = 1. Since the source contains 2 structs (Point and Config), the counts should include Struct: 2.

Apply this diff to correct the chunk counts:

     total_chunks: 3,
     chunk_counts: {
         File: 1,
-        Function: 0,
+        Struct: 2,
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
total_chunks: 3,
chunk_counts: {
File: 1,
Function: 0,
}
total_chunks: 3,
chunk_counts: {
File: 1,
Struct: 2,
}
🤖 Prompt for AI Agents
In tests/integration/languages/zig/extractor.rs around lines 38 to 42, the
chunk_counts map is incomplete: total_chunks is 3 but chunk_counts only lists
File:1 and Function:0 (sum 1); add an entry for Struct: 2 so chunk_counts sums
to 3 and matches total_chunks. Ensure formatting matches existing map style and
ordering if needed.

Comment on lines +70 to +74
total_chunks: 5,
chunk_counts: {
File: 1,
Function: 3,
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Incomplete chunk_counts specification.

The total_chunks expects 5, but chunk_counts only accounts for File:1 + Function:3 = 4. Since the source contains the Vector struct in addition to 3 functions, the counts should include Struct: 1.

Apply this diff to correct the chunk counts:

     total_chunks: 5,
     chunk_counts: {
         File: 1,
+        Struct: 1,
         Function: 3,
     }
🤖 Prompt for AI Agents
In tests/integration/languages/zig/extractor.rs around lines 70 to 74, the
chunk_counts map is missing the Struct entry causing total_chunks (5) to not
match the summed counts; add "Struct: 1" to chunk_counts so File:1 + Function:3
+ Struct:1 = 5, keeping the existing formatting and comma placement.

@unhappychoice unhappychoice merged commit 3ab034e into main Oct 5, 2025
5 of 7 checks passed
@unhappychoice unhappychoice deleted the feature/add-zig-language-support branch October 5, 2025 18:15
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.

feat: Add Zig language support

1 participant