feat(highlight): add C and C++ syntax highlighting#155
Open
BogdanFloris wants to merge 1 commit into
Open
Conversation
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)
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.
Adds tree-sitter-based syntax highlighting for C and C++, following the same pattern as the Zig PR (#144).
Coverage
.c,.h.cpp,.cc,.cxx,.hpp,.hh,.hxx.his parsed as C to keep the C/C++ split clean; in practice this works well for real-world headers.Changes
Cargo.toml— addtree-sitter-candtree-sitter-cpp, both pinned to0.23for ABI v14 compatibility with the project'stree-sitter = "0.24"(0.24+ moved to ABI v15 and won't load under the currenttree-sitter-highlight).src/command/diff/highlight/queries.rs— hand-curatedC_HIGHLIGHTSandCPP_HIGHLIGHTSmapped to lumen's existingHIGHLIGHT_NAMEScapture set (comments, strings, numbers, keywords, types, functions, preprocessor directives, operators, punctuation). C++ also coversnamespace_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 inCONFIGSvia the existingload_confighelper.src/command/diff/highlight/mod.rs— extendtest_all_configs_load; addtest_c_highlightingandtest_cpp_highlighting(the C++ test assertsnamespaceandtemplateare highlighted as keywords).Verification
cargo buildcleancargo test— 128/128 pass (12/12 highlight tests including the 2 new ones)cargo clippy --all-targets— no new warnings in the highlight modulenix profile install .and ranlumen diffagainst C/C++ diffs end-to-end