Skip to content

fix(cpp): skip bodiless forward-declaration class nodes#1094

Open
luoyxy wants to merge 1 commit into
colbymchenry:mainfrom
luoyxy:fix/cpp-forward-decl-phantom-class
Open

fix(cpp): skip bodiless forward-declaration class nodes#1094
luoyxy wants to merge 1 commit into
colbymchenry:mainfrom
luoyxy:fix/cpp-forward-decl-phantom-class

Conversation

@luoyxy

@luoyxy luoyxy commented Jul 1, 2026

Copy link
Copy Markdown

Summary

  • A C++ class Foo; forward declaration parses as a bodiless class_specifier.
    extractClass minted a class node for it, unlike extractStruct (C# Records are not Indexed #831) and
    extractEnum which already skip their bodiless forms. In large C++/Unreal
    codebases a hot type (e.g. APXCharacter) is forward-declared across dozens of
    headers, filling the graph with phantom bodiless nodes that compete with — and
    in codegraph_explore results mask — the single real definition.
  • Adds an opt-in skipBodilessClass flag on LanguageExtractor, enabled for the
    C/C++ extractor where a bodiless class is always a forward declaration.
    Kotlin class Empty / Scala (bodiless = complete definition) are unaffected.

Changes

  • src/extraction/tree-sitter-types.ts: add skipBodilessClass?: boolean.
  • src/extraction/tree-sitter.ts: extractClass resolves body up front and
    returns early when bodiless and the flag is set.
  • src/extraction/languages/c-cpp.ts: set skipBodilessClass: true on cppExtractor.
  • __tests__/cpp-forward-decl.test.ts: regression coverage.

Test plan

  • npx vitest run __tests__/cpp-forward-decl.test.ts (5 passing)
  • npx tsc --noEmit
  • Kotlin bodiless class no-regression covered

A C++ `class Foo;` forward declaration parses as a bodiless
`class_specifier`. `extractClass` created a `class` node for it anyway,
unlike `extractStruct` (colbymchenry#831) and `extractEnum`, which already skip their
bodiless forms. In a large C++/Unreal codebase a hot type such as
`APXCharacter` is forward-declared across dozens of headers, so the graph
filled with phantom bodiless `APXCharacter` nodes that competed with — and
in `codegraph_explore` results masked — the single real definition.

Add an opt-in `skipBodilessClass` flag to LanguageExtractor and enable it
for the C/C++ extractor, where a bodiless class is always a forward
declaration. Languages where a bodiless class is a complete definition
(Kotlin `class Empty`, Scala) are unaffected.

Adds __tests__/cpp-forward-decl.test.ts covering fwd-decl skip, real
definition retained, mixed fwd-decl + definition, templated fwd-decl, and
the Kotlin no-regression case.

Co-authored-by: Cursor <cursoragent@cursor.com>
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