1
0
mirror of https://github.com/sharkdp/bat synced 2026-07-30 18:11:44 +00:00

Handle file extension conflicts in --list-languages (#1076)

This commit is contained in:
Kienyew
2020-08-08 12:01:02 +08:00
committed by David Peter
parent a4ffc9d5ed
commit f97634011e
2 changed files with 27 additions and 6 deletions
+13
View File
@@ -86,6 +86,19 @@ pub fn list_languages(config: &Config) -> Result<()> {
.filter(|syntax| !syntax.hidden && !syntax.file_extensions.is_empty())
.cloned()
.collect::<Vec<_>>();
for lang in languages.iter_mut() {
let lang_name = lang.name.clone();
lang.file_extensions.retain(|extension| {
let test_file = Path::new("test").with_extension(extension);
match config.syntax_mapping.get_syntax_for(test_file) {
Some(MappingTarget::MapTo(primary_lang)) => lang_name == primary_lang,
Some(MappingTarget::MapToUnknown) => true,
None => true,
}
});
}
languages.sort_by_key(|lang| lang.name.to_uppercase());
let configured_languages = get_syntax_mapping_to_paths(config.syntax_mapping.mappings());