Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/languages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub fn language_by_filename(path: &Path) -> Option<Arc<Language>> {
"tsx" => language_by_name("tsx"),
"ts" | "cts" | "mts" => language_by_name("typescript"),
"java" | "groovy" | "gvy" | "gy" | "gsh" => language_by_name("java"),
"cpp" | "cxx" | "cc" | "h" | "hh" => language_by_name("cpp"),
"cpp" | "cxx" | "cc" | "h" | "hh" | "hpp" | "hxx" | "h++" => language_by_name("cpp"),
"sh" | "zsh" | "bash" => language_by_name("shell"),
"cs" => language_by_name("csharp"),
"html" => language_by_name("html"),
Expand Down
16 changes: 15 additions & 1 deletion crates/languages/src/lib_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::{load_language, SUPPORTED_LANGUAGES};
use std::path::Path;

use crate::{language_by_filename, load_language, SUPPORTED_LANGUAGES};

/// Validate that every supported language can be loaded successfully.
/// This catches invalid node types, syntax errors, and other issues in .scm query files
Expand All @@ -20,3 +22,15 @@ fn all_supported_languages_load_successfully() {
.join("\n")
);
}

/// Modern C++ codebases (Boost, Qt, etc.) use `.hpp` (and less often
/// `.hxx` / `.h++`) for headers to distinguish them from plain C.
/// Make sure each variant resolves to the C++ language.
#[test]
fn cpp_header_extensions_resolve_to_cpp() {
for name in ["foo.hpp", "foo.hxx", "foo.h++"] {
let language = language_by_filename(Path::new(name))
.unwrap_or_else(|| panic!("`{name}` should resolve to a language"));
assert_eq!(language.display_name, "C++", "{name} should map to C++");
}
}
Loading