Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(graph): pair Objective-C .h and .m header/implementation files (#2323)

Nehal kanak kuniyil thottathil4903684904a6
diff --git a/packages/core/src/repowise/core/ingestion/graph/_resolvers.py b/packages/core/src/repowise/core/ingestion/graph/_resolvers.py
index 9cb8e20b4..e0ad6b692 100644
--- a/packages/core/src/repowise/core/ingestion/graph/_resolvers.py
+++ b/packages/core/src/repowise/core/ingestion/graph/_resolvers.py
@@ -281,7 +281,8 @@ class ResolveMixin:
done(phase)
def _resolve_cpp_header_pairs(self, progress: Any | None = None) -> None:
- """Pair C/C++ headers with their same-stem same-dir implementations.
+ """Pair C/C++/Objective-C headers with their same-stem same-dir
+ implementations.
``foo.c`` → ``foo.h`` exists via the #include, but nothing ever
points ``foo.h`` → ``foo.c`` — so a consumer that includes the
@@ -301,13 +302,19 @@ class ResolveMixin:
".cpp",
".cxx",
".c++",
+ # Objective-C and Objective-C++. Both carry ``language ==
+ # "objectivec"`` (``specs/objectivec.py`` claims ``.m`` and
+ # ``.mm``; nothing maps ``.mm`` to cpp), so without them the
+ # language gate below has nothing to admit for an ObjC repo.
+ ".m",
+ ".mm",
*sorted(INCLUDE_FRAGMENT_EXTENSIONS),
)
cpp_files = [
p
for p, pf in self._parsed_files.items()
- if pf.file_info.language in ("c", "cpp")
+ if pf.file_info.language in ("c", "cpp", "objectivec")
]
if not cpp_files:
return
diff --git a/tests/unit/ingestion/test_cpp_header_pairs.py b/tests/unit/ingestion/test_cpp_header_pairs.py
index 72947c883..5817566d7 100644
--- a/tests/unit/ingestion/test_cpp_header_pairs.py
+++ b/tests/unit/ingestion/test_cpp_header_pairs.py
@@ -47,3 +47,41 @@ class TestCppHeaderSourcePairing:
# Conservative: same-dir only (recorded cut — include/ vs src/
# layouts pair through the target fan-out instead).
assert not graph.has_edge("include/util.h", "src/util.c")
+
+
+class TestObjectiveCHeaderSourcePairing:
+ def test_header_pairs_with_objc_implementation(self, tmp_path: Path) -> None:
+ (tmp_path / "Foo.h").write_text(
+ '#import <Foundation/Foundation.h>\n'
+ "@interface Foo : NSObject\n"
+ "- (void)bar;\n"
+ "@end\n"
+ )
+ (tmp_path / "Foo.m").write_text(
+ '#import "Foo.h"\n'
+ "@implementation Foo\n"
+ "- (void)bar {}\n"
+ "@end\n"
+ )
+ (tmp_path / "main.m").write_text('#import "Foo.h"\nint main(void) { return 0; }\n')
+ graph = _build(tmp_path)
+ # Foo.m -> Foo.h (import), Foo.h -> Foo.m (pairing). Objective-C
+ # carries its own language tag, and the pairing producer must admit
+ # it: a consumer of the header has to reach the implementation.
+ pair = graph.get_edge_data("Foo.h", "Foo.m")
+ assert pair is not None
+ assert pair.get("hint_source") == "header_source_pair"
+ assert nx.has_path(graph, "main.m", "Foo.m")
+
+ def test_header_pairs_with_objcpp_implementation(self, tmp_path: Path) -> None:
+ (tmp_path / "Foo.h").write_text(
+ '#import <Foundation/Foundation.h>\n'
+ "@interface Foo : NSObject\n"
+ "@end\n"
+ )
+ # .mm is Objective-C++ and routes as the `objectivec` tag, not `cpp`.
+ (tmp_path / "Foo.mm").write_text('#import "Foo.h"\n@implementation Foo\n@end\n')
+ graph = _build(tmp_path)
+ pair = graph.get_edge_data("Foo.h", "Foo.mm")
+ assert pair is not None
+ assert pair.get("hint_source") == "header_source_pair"