fix(cpp): skip bodiless forward-declaration class nodes#1094
Open
luoyxy wants to merge 1 commit into
Open
Conversation
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>
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.
Summary
class Foo;forward declaration parses as a bodilessclass_specifier.extractClassminted aclassnode for it, unlikeextractStruct(C# Records are not Indexed #831) andextractEnumwhich already skip their bodiless forms. In large C++/Unrealcodebases a hot type (e.g.
APXCharacter) is forward-declared across dozens ofheaders, filling the graph with phantom bodiless nodes that compete with — and
in
codegraph_exploreresults mask — the single real definition.skipBodilessClassflag onLanguageExtractor, enabled for theC/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: addskipBodilessClass?: boolean.src/extraction/tree-sitter.ts:extractClassresolves body up front andreturns early when bodiless and the flag is set.
src/extraction/languages/c-cpp.ts: setskipBodilessClass: trueon 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