Make syntax detection more consistent for Reader and File inputs

This commit is contained in:
Ethan P 2020-05-11 19:22:13 -07:00
parent 48441b99ef
commit f39487fca9
No known key found for this signature in database
GPG key ID: 6963FD04F6CF35EA

View file

@ -218,7 +218,7 @@ impl HighlightingAssets {
}
}
}
OpenedInputKind::StdIn | OpenedInputKind::CustomReader => {
OpenedInputKind::StdIn => {
if let Some(ref name) = input.metadata.user_provided_name {
self.get_extension_syntax(&name)
.or_else(|| self.get_first_line_syntax(&mut input.reader))
@ -226,6 +226,29 @@ impl HighlightingAssets {
self.get_first_line_syntax(&mut input.reader)
}
}
OpenedInputKind::CustomReader => {
if let Some(ref path_str) = input.metadata.user_provided_name {
let path = Path::new(path_str);
let absolute_path =
path.canonicalize().ok().unwrap_or_else(|| path.to_owned());
let line_syntax = self.get_first_line_syntax(&mut input.reader);
match mapping.get_syntax_for(path_str) {
Some(MappingTarget::MapTo(syntax_name)) => {
println!("Mapped {:?} as {:?}", path_str, syntax_name);
self.syntax_set.find_syntax_by_name(syntax_name)
}
Some(MappingTarget::MapToUnknown) => line_syntax,
None => {
println!("Test {:?}", path_str);
let file_name = path.file_name().unwrap_or_default();
self.get_extension_syntax(file_name).or(line_syntax)
}
}
} else {
self.get_first_line_syntax(&mut input.reader)
}
}
OpenedInputKind::ThemePreviewFile => self.syntax_set.find_syntax_by_name("Rust"),
}
};