fix(extraction/cpp): keep export-macro-annotated classes and their extends edge (#946)#1062
Open
luoyxy wants to merge 1 commit into
Open
fix(extraction/cpp): keep export-macro-annotated classes and their extends edge (#946)#1062luoyxy wants to merge 1 commit into
luoyxy wants to merge 1 commit into
Conversation
…tends edge (colbymchenry#946) UE-style classes annotated with an ALL-CAPS `*_API` export macro (`class MYMODULE_API Name : public Base { ... }`) were dropped entirely: tree-sitter has no preprocessor, so it reads `class MYMODULE_API` as an elaborated type specifier and the whole declaration as a function_definition named after the class. `isMacroMisparsedTypeDecl` then drops that phantom function as unrecoverable, so the class node AND its base/`extends` edge are lost. As a result, subclass / type-hierarchy / inheritance-impact queries return nothing for what is effectively every gameplay class in a UE project. Add a `preParse` hook (`blankCppExportMacros`) to `cppExtractor` that blanks the export macro with equal-length spaces before parsing -- the same offset-preserving technique `blankCsharpPreprocessorDirectives` uses (colbymchenry#237). The header then parses as an ordinary `class_specifier` with a `base_class_clause`, so the class is indexed and the existing base-clause extraction emits the `extends` edge, with every symbol's line/column unchanged. Scope is deliberately tight to avoid touching valid code: an ALL-CAPS (>=2 char) macro token, only between `class`/`struct` and the type name (two identifiers in a row -- a genuine definition never has that), and only when the type name is followed by `final`, a base clause (`:`) or the body (`{`). `class Foo {`, `template<class T>`, `enum class E {`, and an ALL-CAPS class name with no macro (`class FOO : public Bar`) are all left untouched. The existing `isMacroMisparsedTypeDecl` drop path is kept as a fallback for forms this doesn't cover (function-like macros, macros with lowercase letters). The existing colbymchenry#946 tests are upgraded from "phantom function is absent" to the stronger "class node + extends edge are present", plus unit tests for `blankCppExportMacros` covering offset preservation and non-matching cases. 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
UE-style classes annotated with an ALL-CAPS
*_APIexport macro(
class MYMODULE_API Name : public Base { ... }) are dropped entirely today.tree-sitter has no preprocessor, so it reads
class MYMODULE_APIas anelaborated type specifier and the whole declaration as a
function_definition;isMacroMisparsedTypeDeclthen drops that phantom as unrecoverable. The result:the class node AND its
extendsedge are lost, so subclass / type-hierarchy /inheritance-impact queries return nothing for effectively every gameplay class
in an Unreal Engine project.
Fix
Add a
preParsehook (blankCppExportMacros) tocppExtractorthat blanks theexport macro with equal-length spaces before parsing — the same offset-preserving
technique
blankCsharpPreprocessorDirectivesuses (#237). The header then parsesas an ordinary
class_specifierwith abase_class_clause, so the class isindexed and the existing base-clause extraction emits the
extendsedge, withevery symbol's line/column unchanged.
Scope is deliberately tight to avoid touching valid code: ALL-CAPS (>=2 char)
macro token, only between
class/structand the type name (two identifiers ina row — a genuine definition never has that), and only when the type name is
followed by
final, a base clause (:) or the body ({).class Foo {,template<class T>,enum class E {, and an ALL-CAPS class name with no macro(
class FOO : public Bar) are all untouched. The existingisMacroMisparsedTypeDecldrop path is kept as a fallback for forms this doesn'tcover (function-like macros, macros with lowercase letters).
Tests
extendsedge present" (bothclassandstructvariants).blankCppExportMacros: offset/length preservation,finalandbody-only headers, and non-matching cases left untouched.