@@ -317,8 +317,21 @@ fn directory_distance(a: &str, b: &str) -> usize {
317317/// separate families would reject huge amounts of legitimate same-project
318318/// resolution. Every other `LanguageKind` variant keeps its own family,
319319/// preserving `from_extension`'s existing per-language extension groupings
320- /// (e.g. C's `.c`+`.h`, C++'s `.cpp`/`.cc`/`.cxx`/`.hpp`).
320+ /// (e.g. C's `.c`+`.h`, C++'s `.cpp`/`.cc`/`.cxx`/`.hpp`) — EXCEPT `.h`,
321+ /// treated as ambiguous (returns `None`) rather than inheriting
322+ /// `from_extension`'s C-only mapping: `from_extension` needs one canonical
323+ /// grammar per extension, but a `.h` header is real-world ambiguous between
324+ /// C and C++, and the extremely common case of a `.cpp` file calling into
325+ /// its own project's `.h` header would otherwise be misclassified as
326+ /// cross-language and rejected outright — a real regression from the
327+ /// pre-#1783 same-directory score of 0.7 (Greptile review). This keeps the
328+ /// C/C++-header case working without merging C and C++ source-file families
329+ /// wholesale (`.c` vs `.cpp` intentionally do NOT merge — see
330+ /// is_same_language_family_does_not_merge_c_and_cpp).
321331fn language_family ( file : & str ) -> Option < LanguageKind > {
332+ if file. to_ascii_lowercase ( ) . ends_with ( ".h" ) {
333+ return None ;
334+ }
322335 match LanguageKind :: from_extension ( file) {
323336 Some ( LanguageKind :: TypeScript ) | Some ( LanguageKind :: Tsx ) => Some ( LanguageKind :: JavaScript ) ,
324337 other => other,
@@ -635,6 +648,15 @@ mod tests {
635648 assert ! ( is_same_language_family( "src/a.c" , "src/a.h" ) ) ;
636649 }
637650
651+ #[ test]
652+ fn is_same_language_family_treats_h_as_ambiguous_with_cpp ( ) {
653+ // Greptile follow-up to #1783: `.h` is real-world ambiguous between C
654+ // and C++ (LANGUAGE_REGISTRY/from_extension assigns it to C alone for
655+ // grammar-selection purposes), so a `.cpp` file calling into its own
656+ // project's `.h` header must not be rejected as cross-language.
657+ assert ! ( is_same_language_family( "src/widget.cpp" , "src/widget.h" ) ) ;
658+ }
659+
638660 #[ test]
639661 fn is_same_language_family_merges_cpp_source_and_header_variants ( ) {
640662 assert ! ( is_same_language_family( "src/a.cpp" , "src/a.hpp" ) ) ;
0 commit comments