Skip to content

feat(lang): add C and C++ language support#2746

Merged
marschattha merged 4 commits intomainfrom
feat/c-cpp-maintainability-support
Apr 15, 2026
Merged

feat(lang): add C and C++ language support#2746
marschattha merged 4 commits intomainfrom
feat/c-cpp-maintainability-support

Conversation

@davehenton
Copy link
Copy Markdown
Member

Summary

  • Add tree-sitter-based C and C++ language implementations for maintainability analysis (complexity, duplication, nested control flow, etc.)
  • Wire up tree-sitter dependencies, language registration in ALL_LANGS, file type/extension mappings, and protobuf enum mappings
  • Add integration test fixtures and test registration for both C and C++

Test plan

  • Unit tests pass for both C and C++ language modules (11 tests)
  • Integration tests pass for both c_tests and cpp_tests
  • cargo check passes cleanly
  • CI passes

🤖 Generated with Claude Code

davehenton and others added 2 commits April 8, 2026 19:27
Wire up tree-sitter-based C and C++ language implementations including
tree-sitter dependencies, language registration, file type/extension
mappings, protobuf enum mappings, and integration tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add test fixtures and test registration for C language support,
mirroring the existing C++ test structure.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@qltysh
Copy link
Copy Markdown
Contributor

qltysh bot commented Apr 9, 2026

Qlty


Coverage Impact - ubuntu-latest

⬆️ Merging this pull request will increase total coverage on main by 0.14%.

Modified Files with Diff Coverage (3)

RatingFile% DiffUncovered Line #s
Coverage rating: D Coverage rating: D
qlty-types/src/lib.rs100.0%
New Coverage rating: A
qlty-analysis/src/lang/c.rs99.0%205, 227
New Coverage rating: A
qlty-analysis/src/lang/cpp.rs99.1%229, 243
Total99.0%
🤖 Increase coverage with AI coding...
In the `feat/c-cpp-maintainability-support` branch, add test coverage for this new code:

- `qlty-analysis/src/lang/c.rs` -- Lines 205 and 227
- `qlty-analysis/src/lang/cpp.rs` -- Lines 229 and 243

🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

@qltysh
Copy link
Copy Markdown
Contributor

qltysh bot commented Apr 9, 2026

Qlty


Coverage Impact - macos-15

⬆️ Merging this pull request will increase total coverage on main by 0.13%.

Modified Files with Diff Coverage (3)

RatingFile% DiffUncovered Line #s
Coverage rating: D Coverage rating: D
qlty-types/src/lib.rs100.0%
New Coverage rating: A
qlty-analysis/src/lang/c.rs99.0%205, 227
New Coverage rating: A
qlty-analysis/src/lang/cpp.rs99.1%229, 243
Total99.0%
🤖 Increase coverage with AI coding...
In the `feat/c-cpp-maintainability-support` branch, add test coverage for this new code:

- `qlty-analysis/src/lang/c.rs` -- Lines 205 and 227
- `qlty-analysis/src/lang/cpp.rs` -- Lines 229 and 243

🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

@davehenton davehenton marked this pull request as ready for review April 9, 2026 20:57
Copy link
Copy Markdown
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization's overage spend limit has been reached.

Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit at claude.ai/admin-settings/claude-code.

Once credits are available, reopen this pull request to trigger a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds first-class C and C++ support to qlty’s tree-sitter-based maintainability analysis pipeline, wiring language registration/config globs and providing CLI integration fixtures to exercise the end-to-end flow.

Changes:

  • Introduce new c and cpp language implementations in qlty-analysis and register them in ALL_LANGS.
  • Add workspace dependencies (tree-sitter-c, tree-sitter-cpp) and protobuf/enum + default config mappings for c/cpp.
  • Add CLI integration fixtures and test registration for C and C++.

Reviewed changes

Copilot reviewed 28 out of 29 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
qlty-types/src/lib.rs Maps "c"/"cpp" string names to protobuf Language enums.
qlty-config/default.toml Adds file_types and language glob mappings for C/C++.
qlty-cli/tests/lang/cpp/basic.toml Adds a basic C++ CLI integration test case.
qlty-cli/tests/lang/cpp/basic.in/Returns.cpp C++ fixture for return-statements behavior.
qlty-cli/tests/lang/cpp/basic.in/parameters.cpp C++ fixture for parameter counting behavior.
qlty-cli/tests/lang/cpp/basic.in/NestedControl.cpp C++ fixture for nested control-flow behavior.
qlty-cli/tests/lang/cpp/basic.in/Identical.cpp C++ fixture for identical-code behavior.
qlty-cli/tests/lang/cpp/basic.in/FunctionComplexity.cpp C++ fixture for function complexity behavior.
qlty-cli/tests/lang/cpp/basic.in/FileComplexity.cpp C++ fixture for file complexity behavior.
qlty-cli/tests/lang/cpp/basic.in/BooleanLogic.cpp C++ fixture for boolean-logic behavior.
qlty-cli/tests/lang/cpp/basic.in/.qlty/qlty.toml Minimal per-fixture qlty config for C++ tests.
qlty-cli/tests/lang/cpp/basic.in/.gitignore Ignores generated .qlty/ outputs in C++ fixtures.
qlty-cli/tests/lang/c/basic.toml Adds a basic C CLI integration test case.
qlty-cli/tests/lang/c/basic.in/returns.c C fixture for return-statements behavior.
qlty-cli/tests/lang/c/basic.in/parameters.c C fixture for parameter counting behavior.
qlty-cli/tests/lang/c/basic.in/nested_control.c C fixture for nested control-flow behavior.
qlty-cli/tests/lang/c/basic.in/identical.c C fixture for identical-code behavior.
qlty-cli/tests/lang/c/basic.in/function_complexity.c C fixture for function complexity behavior.
qlty-cli/tests/lang/c/basic.in/file_complexity.c C fixture for file complexity behavior.
qlty-cli/tests/lang/c/basic.in/boolean_logic.c C fixture for boolean-logic behavior.
qlty-cli/tests/lang/c/basic.in/.qlty/qlty.toml Minimal per-fixture qlty config for C tests.
qlty-cli/tests/lang/c/basic.in/.gitignore Ignores generated .qlty/ outputs in C fixtures.
qlty-cli/tests/lang.rs Registers c_tests and cpp_tests in the CLI test suite.
qlty-analysis/src/lang/cpp.rs Implements C++ AST node kinds + queries and identifier extraction via tree-sitter-cpp.
qlty-analysis/src/lang/c.rs Implements C AST node kinds + queries and identifier extraction via tree-sitter-c.
qlty-analysis/src/lang.rs Adds mod c; mod cpp; and registers them in ALL_LANGS.
qlty-analysis/Cargo.toml Adds tree-sitter-c and tree-sitter-cpp workspace dependencies.
Cargo.toml Adds workspace package versions for tree-sitter-c and tree-sitter-cpp.
Cargo.lock Locks new tree-sitter C/C++ crates and their transitive deps.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread qlty-analysis/src/lang/c.rs Outdated
Comment thread qlty-analysis/src/lang/c.rs
Comment thread qlty-analysis/src/lang/cpp.rs Outdated
davehenton and others added 2 commits April 10, 2026 20:21
…tegration test snapshots

Fix missing else_nodes() for both C and C++ so else-if chains no longer
incorrectly inflate nesting depth and cognitive complexity. Fix
FUNCTION_DECLARATION_QUERY to match pointer-returning functions via
pointer_declarator alternative. Fix C++ call_identifiers returning
(Some("this"), name) for free functions. Move C++ constants to associated
constants and remove dead code. Add basic.stdout snapshot files so
integration tests verify actual analysis output.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ll tracking

Move *.h from C-only to C++ file_type/language globs since C++ grammar
is a superset and C headers still parse correctly, while C++ headers
were silently producing zero analysis. Fix call_identifiers to return
Some("this") for bare function calls (matching Python/C# pattern) so
LCOM correctly tracks implicit member calls. Add field_expression to
field_nodes so explicit this->x access is also visible to LCOM.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@marschattha
Copy link
Copy Markdown
Member

Follow-up fix: .h header routing + LCOM bare member call tracking

Two bugs were identified and fixed in b7e5fb3:

1. .h headers analyzed as C instead of C++ (High)

*.h was only in the C file_type/language globs, so C++ headers like Header.h were routed to the C parser — which can't parse class, namespace, template, etc. This caused those files to silently produce classes: 0, functions: 0.

Fix: Moved *.h from C-only to C++ globs in default.toml. The C++ tree-sitter grammar is a superset of C, so pure C headers still parse correctly. C++ headers now get the correct parser.

2. LCOM drops bare member calls in C++ (Medium)

call_identifiers() returned (None, "b") for bare b() calls inside methods. Since LCOM only records calls where receiver == self_keyword ("this"), all implicit member calls were silently dropped — producing lcom4: 0 for classes that should have had cohesion.

Fix: Bare identifier calls now return (Some("this"), name), matching the established Python/C# pattern. Also added field_expression to field_nodes() so explicit this->x field access is visible to LCOM's visit_field.

Local repro confirmed: class Foo { int x; void a() { x = 1; b(); } void b() { x = 2; } } now correctly reports lcom4: 1.

@marschattha marschattha merged commit a56a8f3 into main Apr 15, 2026
19 checks passed
@marschattha marschattha deleted the feat/c-cpp-maintainability-support branch April 15, 2026 18:09
davehenton added a commit that referenced this pull request Apr 16, 2026
PR #2746 (a56a8f3) merged C/C++ language support to main, touching the
same shared registration files this branch modifies. Add a Prerequisites
section noting the rebase onto origin/main and the published-crate
grammar path confirmed by the C/C++ merge, and make c_tests/cpp_tests
unconditional in the Task 3 completion gate now that they exist.
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.

3 participants