Skip to content

[repo-assist] feat: add C++ cognitive complexity analyzer #508

Description

@github-actions

🤖 This pull request was created by Repo Assist, an automated AI assistant.

Summary

Adds cognitive complexity analysis for C++ source files, bringing the extension's language coverage to 10 languages (C#, Go, Java, JS, TS, Python, Rust, TSX, JSX, and now C++).


What's New

src/metricsAnalyzer/languages/cppAnalyzer.ts (new)

CppMetricsAnalyzer uses tree-sitter-cpp@0.23.4 to parse C++ and calculates cognitive complexity for all function_definition nodes (free functions, class methods, constructors, destructors, and operator overloads).

Supported complexity constructs:

Construct Increment
if, while, for, for-range, do-while, switch +1 + nesting
try block +1 + nesting
catch clause +1 + nesting
&& / || (per distinct chain) +1 flat
Ternary ?: +1 flat
Lambda expression (when nested) +1 + nesting
break / continue (inside nesting) +1 flat
goto +1 flat
  • Qualified naming: methods and operators inside classes are reported as ClassName::methodName or ClassName::operator==
  • Out-of-line definitions (Foo::bar() defined outside the class) use the fully-qualified name from the declarator
  • Lambdas are collected as separate analysis entries; a top-level lambda (not inside any nesting construct) does not add to the enclosing function's score

src/metricsAnalyzer/metricsAnalyzerFactory.ts

Registers cpp as a supported language ID.

package.json

  • Adds tree-sitter-cpp@0.23.4 as a runtime dependency (compatible with the existing tree-sitter@0.21.1 peer constraint)
  • Adds onLanguage:cpp activation event
  • Adds cpp and c++ to keywords

samples/Test.cpp

Sample C++ file with annotated complexity scores for manual extension testing.


Dependency note

tree-sitter-cpp@0.23.4 declares peerDependencies: { "tree-sitter": "^0.21.1" } which matches the current pinned tree-sitter@0.21.1, so no version bump is required.


Test Status

npm run compile  ✅  (0 errors)
npm run lint     ✅  (0 warnings)
npm run test:unit  ✅  225 passing (was 201), 0 failing

Coverage (analyzer/factory code, VS Code-API files excluded):

  • All coverage thresholds met (no threshold violations)
  • cppAnalyzer.ts: 94.87% stmts, 87.5% branches, 100% functions

Warning

Protected Files — Push Permission Denied

This was originally intended as a pull request, but the patch modifies protected files. A human must create the pull request manually.

Protected files
  • package.json

The push was rejected because GitHub Actions does not have workflows permission to push these changes, and is never allowed to make such changes, or other authorization being used does not have this permission.

Create the pull request manually
# Download the patch from the workflow run
gh run download 30913641687 -n agent -D /tmp/agent-30913641687

# Create a new branch
git checkout -b repo-assist/feat-cpp-support-20260804-ac6a6b61a5392712 main

# Apply the patch (--3way handles cross-repo patches)
git am --3way /tmp/agent-30913641687/aw-repo-assist-feat-cpp-support-20260804.patch

# Push the branch and create the pull request
git push origin repo-assist/feat-cpp-support-20260804-ac6a6b61a5392712
gh pr create --title '[repo-assist] feat: add C++ cognitive complexity analyzer' --base main --head repo-assist/feat-cpp-support-20260804-ac6a6b61a5392712 --repo askpt/code-metrics

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • releaseassets.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

Generated by 🌈 Repo Assist, see workflow run. Learn more.
Comment /repo-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@42c2ab5b4e4c9273534c39259b2e0df7f20f07e9

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions