Move header checks out of from_extension

pull/230/head
Wilfred Hughes 2022-04-01 22:24:12 +07:00
parent 97b9a13d15
commit e3d91d6dcc
1 changed files with 6 additions and 3 deletions

@ -62,7 +62,10 @@ pub fn guess(path: &Path, src: &str) -> Option<Language> {
} }
match path.extension() { match path.extension() {
Some(extension) => from_extension(extension, src), Some(extension) => match from_extension(extension) {
Some(Language::Php) if src.starts_with("<?hh") => None,
language => language,
},
None => None, None => None,
} }
} }
@ -169,7 +172,7 @@ fn from_name(path: &Path) -> Option<Language> {
} }
} }
fn from_extension(extension: &OsStr, src: &str) -> Option<Language> { fn from_extension(extension: &OsStr) -> Option<Language> {
match extension.to_string_lossy().borrow() { match extension.to_string_lossy().borrow() {
"sh" | "bash" | "bats" | "cgi" | "command" | "env" | "fcgi" | "ksh" | "sh.in" | "tmux" "sh" | "bash" | "bats" | "cgi" | "command" | "env" | "fcgi" | "ksh" | "sh.in" | "tmux"
| "tool" | "zsh" => Some(Bash), | "tool" | "zsh" => Some(Bash),
@ -201,7 +204,7 @@ fn from_extension(extension: &OsStr, src: &str) -> Option<Language> {
"nix" => Some(Nix), "nix" => Some(Nix),
"ml" => Some(OCaml), "ml" => Some(OCaml),
"mli" => Some(OCamlInterface), "mli" => Some(OCamlInterface),
"php" if !src.starts_with("<?hh") => Some(Php), "php" => Some(Php),
"py" | "py3" | "pyi" | "bzl" => Some(Python), "py" | "py3" | "pyi" | "bzl" => Some(Python),
"rb" | "builder" | "spec" | "rake" => Some(Ruby), "rb" | "builder" | "spec" | "rake" => Some(Ruby),
"rs" => Some(Rust), "rs" => Some(Rust),