Skip to content

feat(graph): add cross-file Class-to-Function CONTAINS linking#735

Open
jannahopp wants to merge 1 commit intoCodeGraphContext:mainfrom
jannahopp:feat/cross-file-class-method-linking
Open

feat(graph): add cross-file Class-to-Function CONTAINS linking#735
jannahopp wants to merge 1 commit intoCodeGraphContext:mainfrom
jannahopp:feat/cross-file-class-method-linking

Conversation

@jannahopp
Copy link
Copy Markdown
Contributor

Summary

Add cross-file fallback for Class-to-Function CONTAINS edge creation, enabling class_hierarchy and overrides queries to return methods for C++ classes.

Problem

In C/C++, classes are declared in .h files and methods are defined in .cpp files. The existing CONTAINS edge creation matched Class and Function nodes only when they shared the same file path:

MATCH (c:Class {name: $class_name, path: $path})
MATCH (fn:Function {name: $func_name, path: $path, ...})

This never succeeds for C++ method definitions, so class_hierarchy returned 0 methods and overrides returned 0 results for all C++ classes.

Solution

Try the same-file match first (works for Python, JS, etc.), then fall back to matching the Class node by name only:

MATCH (c:Class {name: $class_name})
MATCH (fn:Function {name: $func_name, path: $path, ...})

This requires the Function node to have a class_context property (provided by #734).

Known limitation

The cross-file fallback matches by class name only (no path constraint). Classes with identical names in different files could get false links. The same-file match is always tried first, so this only affects languages with header/implementation file splits (C, C++, Objective-C). This is documented in a code comment.

Impact

On a 300-file C++ codebase:

  • class_hierarchy("QueueElement_Dialer_Export") now returns 1 parent, 3 children, and 42 methods (previously: 0 parents, 0 methods)
  • overrides("execute") now returns 6 implementations across classes (previously: 0)

Depends on

🤖 Generated with Claude Code

In C/C++, classes are declared in .h files and methods are defined in
.cpp files. The existing CONTAINS edge creation matched Class and
Function nodes only when they shared the same file path, which never
succeeds for C++ method definitions.

Add a cross-file fallback: if the same-file match fails, try matching
the Class node by name only (no path constraint) and link it to the
Function node. This enables class_hierarchy and overrides queries to
return methods for C++ classes.

Note: the cross-file match uses class name only, so classes with
identical names in different files could get false links. The same-file
match is always tried first to avoid this for languages where class
and methods share a file (Python, JS, etc.).

Depends on: feat/cpp-parser-improvements (which adds class_context
to Function nodes for qualified C++ method definitions)

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

vercel bot commented Mar 17, 2026

@jannahopp is attempting to deploy a commit to the shashankss1205's projects Team on Vercel.

A member of the Team first needs to authorize it.

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