Skip to content

feat(highlight): add C and C++ syntax highlighting#155

Open
BogdanFloris wants to merge 1 commit into
jnsahaj:mainfrom
BogdanFloris:add-c-cpp-highlighting
Open

feat(highlight): add C and C++ syntax highlighting#155
BogdanFloris wants to merge 1 commit into
jnsahaj:mainfrom
BogdanFloris:add-c-cpp-highlighting

Conversation

@BogdanFloris

Copy link
Copy Markdown

Adds tree-sitter-based syntax highlighting for C and C++, following the same pattern as the Zig PR (#144).

Coverage

  • C.c, .h
  • C++.cpp, .cc, .cxx, .hpp, .hh, .hxx

.h is parsed as C to keep the C/C++ split clean; in practice this works well for real-world headers.

Changes

  • Cargo.toml — add tree-sitter-c and tree-sitter-cpp, both pinned to 0.23 for ABI v14 compatibility with the project's tree-sitter = "0.24" (0.24+ moved to ABI v15 and won't load under the current tree-sitter-highlight).
  • src/command/diff/highlight/queries.rs — hand-curated C_HIGHLIGHTS and CPP_HIGHLIGHTS mapped to lumen's existing HIGHLIGHT_NAMES capture set (comments, strings, numbers, keywords, types, functions, preprocessor directives, operators, punctuation). C++ also covers namespace_identifier, qualified_identifier, template_function/template_method, this, auto, and raw string literals. Node names verified against the grammars' node-types.json.
  • src/command/diff/highlight/config.rs — register all eight extensions in CONFIGS via the existing load_config helper.
  • src/command/diff/highlight/mod.rs — extend test_all_configs_load; add test_c_highlighting and test_cpp_highlighting (the C++ test asserts namespace and template are highlighted as keywords).

Verification

  • cargo build clean
  • cargo test — 128/128 pass (12/12 highlight tests including the 2 new ones)
  • cargo clippy --all-targets — no new warnings in the highlight module
  • Installed locally via nix profile install . and ran lumen diff against C/C++ diffs end-to-end

Adds tree-sitter-based syntax highlighting for C (.c, .h) and
C++ (.cpp, .cc, .cxx, .hpp, .hh, .hxx), following the same registration
pattern as the existing Zig support.

- Cargo.toml: pin tree-sitter-c and tree-sitter-cpp to 0.23 for ABI v14
  compatibility with tree-sitter 0.24
- queries.rs: hand-curated C_HIGHLIGHTS and CPP_HIGHLIGHTS targeting
  lumen's HIGHLIGHT_NAMES capture set (comments, strings, numbers,
  keywords, types, functions, preprocessor, operators, punctuation;
  C++ also covers namespaces, templates, qualified calls, this, auto)
- config.rs: register the eight extensions in CONFIGS
- mod.rs: extend test_all_configs_load and add test_c_highlighting and
  test_cpp_highlighting (asserts namespace/template show up as keywords)
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.

1 participant