Skip to content

feat: add Lua syntax highlighting support - #110

Merged
unhappychoice merged 3 commits into
mainfrom
feat/lua-syntax-highlighting
Nov 26, 2025
Merged

unhappychoice merged 3 commits into
mainfrom
feat/lua-syntax-highlighting

Conversation

@unhappychoice

@unhappychoice unhappychoice commented Nov 26, 2025 •

Copy link
Copy Markdown
Owner

Summary

close: #90

  • Add Lua syntax highlighting support using tree-sitter-lua
  • Sort dependencies and code alphabetically for consistency
  • Organize use statements in standard Rust order (std → external crates → crate modules)

Changes

  • Add tree-sitter-lua dependency
  • Create src/syntax/languages/lua.rs module
  • Sort Cargo.toml dependencies alphabetically
  • Sort TokenType enum and match arms alphabetically
  • Sort use statements across all source files

Test plan

  • cargo check passes
  • cargo test passes
  • cargo clippy passes
  • cargo fmt applied

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added support for Lua, Go, Rust, Python, JavaScript, Ruby, and numerous additional programming languages.
    • Enhanced syntax highlighting with expanded token types and improved color mapping across all supported languages.
  • Chores

    • Updated dependencies to enable broader language parser coverage.

✏️ Tip: You can customize this high-level summary in your review settings.

unhappychoice and others added 3 commits November 27, 2025 01:36
Add tree-sitter-lua dependency and implement Lua language module for
syntax highlighting of .lua files.

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

Co-Authored-By: Claude <[email protected]>
Alphabetically sort TokenType variants, color() match arms, and
highlight() base_name match arms for consistency.

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

Co-Authored-By: Claude <[email protected]>
Organize use statements in standard Rust order:
1. std library
2. External crates (alphabetically)
3. crate modules

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

Co-Authored-By: Claude <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 26, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request restructures project dependencies with a major overhaul including new utility crates (anyhow, chrono, clap, crossterm, etc.) and expanded tree-sitter language parser support. Simultaneously, it refactors the syntax highlighting system by reorganizing the TokenType enum, updating capture-name mappings, and adds Lua language support. Multiple import statements are reordered across pane files for consistency.

Changes

Cohort / File(s) Summary
Dependency Configuration
Cargo.toml
Significant dependency set overhaul: added numerous utility crates (anyhow, chrono, chrono-english, clap with derive, crossterm, ctrlc, dirs, globset, rand, serde with derive, streaming-iterator, toml, toml_edit) and restructured tree-sitter language parsers with expanded language coverage (bash, clojure, css, go, haskell, java, javascript, kotlin-ng, lua, php, python, ruby, rust, scala, zig, yaml).
Animation Timing Configuration
src/animation.rs
Reordered imports and added extensive timing constants for granular animation pacing (cursor movement multipliers, scroll steps, pause durations for various operations like delete, insert, checkout, push, etc.).
Import Reorganization (Panes)
src/panes/editor.rs, src/panes/file_tree.rs, src/panes/status_bar.rs, src/panes/terminal.rs
Reordered use statements moving crate-local imports (CommitMetadata, Theme, SelectableParagraph) to follow standard library and external crate imports, no functional changes.
New Lua Language Support
src/syntax/languages/lua.rs
Added public module exposing language() function returning tree-sitter Lua language representation and HIGHLIGHT_QUERY constant for syntax highlighting queries.
Language Module Registry
src/syntax/languages/mod.rs
Added new lua public module and substantially expanded language detection mapping to support cs, css, dart, go, haskell, java, javascript, json, kotlin, lua, markdown, php, python, ruby, rust, scala, swift, xml, yaml, zig and related file extensions.
Syntax Highlighting System Refactor
src/syntax/mod.rs
Reorganized and expanded TokenType enum variants with reordering to include Comment, Constant, Label, Punctuation variants. Completely revised color() mapping and substantially reworked Highlighter::highlight capture-name dispatch with expanded mappings for annotation, attribute, boolean, character, class, comment, conditional, constant, decorator, delimiter, escape, field, float, identifier, keyword, label, macro, method, module, namespace, number, operator, parameter, property, punctuation, regexp, special, string, text, type, and variable captures.
UI Imports and Widget Styling
src/ui.rs, src/widgets/selectable_paragraph.rs
Added standard library imports (std::io, std::sync::atomic, std::sync::Arc, std::time) and unicode_width utility. Consolidated style import paths in widget module.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • src/syntax/mod.rs: Dense refactoring of TokenType enum, color mapping logic, and capture-name dispatch requires careful verification of all capture-name-to-variant mappings and color routing to ensure no regressions in syntax highlighting across supported languages.
  • Cargo.toml: Substantial dependency restructuring warrants verification that all added crates align with project architecture and that tree-sitter parser versions are compatible.
  • src/syntax/languages/mod.rs: Expanded language detection mapping should be cross-checked against file extension conventions to ensure correctness across all newly supported languages.
  • Import reordering across pane files (editor, file_tree, status_bar, terminal) is repetitive and low-risk but should be spot-checked for consistency.

Possibly related PRs

Poem

🐰 A syntax rainbow now shines so bright,
From Lua's moons to Rust's mighty light,
TokenTypes dance in reordered grace,
Animation timing finds its place,
Dependencies bloom—the garden's alive! 🌿✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add Lua syntax highlighting support' is concise, clear, and directly summarizes the main change—adding Lua syntax highlighting.
Linked Issues check ✅ Passed The PR satisfies issue #90 requirements: it adds Lua syntax highlighting support with appropriate token mappings for keywords, comments, strings, numbers, and operators through tree-sitter-lua integration.
Out of Scope Changes check ✅ Passed All changes are in-scope: Lua syntax highlighting implementation (lua.rs, mod.rs updates), comprehensive dependency overhaul (supporting multiple languages), and import/formatting organization across all files are consistent with the PR's goals.
✨ 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 feat/lua-syntax-highlighting

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 84f77c5 and 6f212b9.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (11)
  • Cargo.toml (1 hunks)
  • src/animation.rs (1 hunks)
  • src/panes/editor.rs (1 hunks)
  • src/panes/file_tree.rs (1 hunks)
  • src/panes/status_bar.rs (1 hunks)
  • src/panes/terminal.rs (1 hunks)
  • src/syntax/languages/lua.rs (1 hunks)
  • src/syntax/languages/mod.rs (2 hunks)
  • src/syntax/mod.rs (2 hunks)
  • src/ui.rs (2 hunks)
  • src/widgets/selectable_paragraph.rs (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/syntax/languages/mod.rs (16)
src/syntax/languages/lua.rs (1)
  • language (1-3)
src/syntax/languages/bash.rs (1)
  • language (1-3)
src/syntax/languages/yaml.rs (1)
  • language (1-3)
src/syntax/languages/markdown.rs (1)
  • language (1-3)
src/syntax/languages/clojure.rs (1)
  • language (1-3)
src/syntax/languages/csharp.rs (1)
  • language (1-3)
src/syntax/languages/css.rs (1)
  • language (1-3)
src/syntax/languages/cpp.rs (1)
  • language (1-3)
src/syntax/languages/elixir.rs (1)
  • language (1-3)
src/syntax/languages/erlang.rs (1)
  • language (1-3)
src/syntax/languages/go_lang.rs (1)
  • language (1-3)
src/syntax/languages/haskell.rs (1)
  • language (1-3)
src/syntax/languages/html.rs (1)
  • language (1-3)
src/syntax/languages/java.rs (1)
  • language (1-3)
src/syntax/languages/javascript.rs (1)
  • language (1-3)
src/syntax/languages/json.rs (1)
  • language (1-3)
⏰ 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). (2)
  • GitHub Check: Build (windows-latest)
  • GitHub Check: Nix Build
🔇 Additional comments (16)
src/ui.rs (1)

1-5: LGTM! Import organization follows Rust conventions.

The imports have been reorganized to follow standard Rust ordering (std → external crates → crate modules), which improves code readability and maintainability. All added imports are used in the existing code.

Also applies to: 20-20

src/animation.rs (2)

3-9: LGTM! Import reorganization follows Rust conventions.

The imports have been reordered to follow standard Rust ordering (std → external crates → crate modules), maintaining consistency with the rest of the codebase.


10-33: LGTM! Expanded timing configuration improves animation control.

The addition of granular timing constants (cursor movement multipliers, scroll steps, pause durations) provides better control over animation pacing and improves code maintainability by centralizing these values.

src/panes/editor.rs (1)

9-12: LGTM! Import reorganization follows Rust conventions.

The imports have been reordered to follow standard Rust ordering (std → external crates → crate modules), consistent with the import reorganization across the codebase.

src/widgets/selectable_paragraph.rs (1)

4-4: LGTM! Consolidated import improves conciseness.

Combining Color and Style into a single import path style::{Color, Style} is more concise and follows Rust conventions for grouping related imports from the same module.

src/panes/file_tree.rs (1)

1-13: LGTM! Import reorganization follows Rust conventions.

The imports have been reordered to follow standard Rust ordering (std → external crates → crate modules), with std::collections::BTreeMap properly placed at the top of the import hierarchy.

src/panes/terminal.rs (1)

9-12: LGTM! Import reorganization follows Rust conventions.

The imports have been reordered to follow standard Rust ordering (std → external crates → crate modules), maintaining consistency with the other pane modules in this PR.

src/panes/status_bar.rs (1)

9-12: LGTM! Import reorganization follows Rust conventions.

The imports have been reordered to follow standard Rust ordering (std → external crates → crate modules), completing the consistent import reorganization across all pane modules.

Cargo.toml (1)

59-59: tree-sitter-lua version 0.2 is the latest stable release with no known security advisories.

Verification confirms:

  • Version 0.2.0 (released 2024-09-09) is the latest stable version on crates.io
  • No security vulnerabilities found in GitHub Security Advisory database
  • No advisories in Rustsec or OSV databases
  • The dependency is safe to add
src/syntax/languages/mod.rs (2)

17-17: LGTM! Lua module correctly declared.

The module declaration is properly placed in alphabetical order and follows the project's conventions.


55-55: LGTM! Lua language mapping correctly integrated.

The match arm for .lua files correctly returns the language parser and highlight query, following the exact pattern used by all other supported languages. This completes the Lua syntax highlighting integration.

src/syntax/mod.rs (4)

12-26: LGTM! Well-structured TokenType expansion.

The enum now includes a comprehensive set of token types (Comment, Constant, Label, Punctuation, String, Type, Variable) in addition to the existing ones. The alphabetical ordering improves maintainability.


28-46: LGTM! Complete color mapping coverage.

All 13 TokenType variants are correctly mapped to their corresponding theme colors. The exhaustive match ensures compile-time verification of completeness.


151-151: LGTM! Proper handling of dotted capture names.

Correctly extracts the base name from dotted capture names (e.g., "keyword.function" → "keyword"), which is the standard approach for tree-sitter highlight queries.


153-192: LGTM! Comprehensive and well-organized capture mappings.

The capture name mappings are extensive and follow tree-sitter conventions:

  • Logical groupings (e.g., class/constructor/enum/interface/struct/trait all map to Type)
  • Semantic consistency (e.g., annotation/attribute/decorator map to Keyword)
  • Proper handling of edge cases (regexp, escape, special)
  • Appropriate skipping of internal markers

The alphabetical ordering and consistent formatting make this maintainable.

src/syntax/languages/lua.rs (1)

1-5: Verification Complete: Implementation Confirmed

The lua.rs module correctly follows the established pattern used across all language modules in the project:

  • Dependency: tree-sitter-lua = "0.2" is declared in Cargo.toml (line 59) ✓
  • Symbol exports: The tree-sitter-lua crate exports LANGUAGE and HIGHLIGHTS_QUERY as expected ✓
  • Pattern consistency: All language modules define a public HIGHLIGHT_QUERY constant that abstracts underlying crate exports. Some crates (like lua, php, yaml, scala) export HIGHLIGHTS_QUERY (plural), while others (bash, c, cpp, javascript) export HIGHLIGHT_QUERY (singular). The lua.rs module correctly maps tree_sitter_lua::HIGHLIGHTS_QUERY to the module's HIGHLIGHT_QUERY constant, consistent with php.rs, yaml.rs, scala.rs, and others ✓

The implementation is clean and correct.


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.

@unhappychoice
unhappychoice merged commit 533cff3 into main Nov 26, 2025
@unhappychoice
unhappychoice deleted the feat/lua-syntax-highlighting branch November 26, 2025 16:42
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 Lua syntax highlighting support

1 participant