Skip to content

Commit 8155450

Browse files
committed
Recognize .hpp/.hxx/.h++ as C++ headers
1 parent c325d14 commit 8155450

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

crates/languages/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub fn language_by_filename(path: &Path) -> Option<Arc<Language>> {
152152
"tsx" => language_by_name("tsx"),
153153
"ts" | "cts" | "mts" => language_by_name("typescript"),
154154
"java" | "groovy" | "gvy" | "gy" | "gsh" => language_by_name("java"),
155-
"cpp" | "cxx" | "cc" | "h" | "hh" => language_by_name("cpp"),
155+
"cpp" | "cxx" | "cc" | "h" | "hh" | "hpp" | "hxx" | "h++" => language_by_name("cpp"),
156156
"sh" | "zsh" | "bash" => language_by_name("shell"),
157157
"cs" => language_by_name("csharp"),
158158
"html" => language_by_name("html"),

crates/languages/src/lib_tests.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::{load_language, SUPPORTED_LANGUAGES};
1+
use std::path::Path;
2+
3+
use crate::{language_by_filename, load_language, SUPPORTED_LANGUAGES};
24

35
/// Validate that every supported language can be loaded successfully.
46
/// This catches invalid node types, syntax errors, and other issues in .scm query files
@@ -20,3 +22,15 @@ fn all_supported_languages_load_successfully() {
2022
.join("\n")
2123
);
2224
}
25+
26+
/// Modern C++ codebases (Boost, Qt, etc.) use `.hpp` (and less often
27+
/// `.hxx` / `.h++`) for headers to distinguish them from plain C.
28+
/// Make sure each variant resolves to the C++ language.
29+
#[test]
30+
fn cpp_header_extensions_resolve_to_cpp() {
31+
for name in ["foo.hpp", "foo.hxx", "foo.h++"] {
32+
let language = language_by_filename(Path::new(name))
33+
.unwrap_or_else(|| panic!("`{name}` should resolve to a language"));
34+
assert_eq!(language.display_name, "C++", "{name} should map to C++");
35+
}
36+
}

0 commit comments

Comments
 (0)