HighlightingAssets: Inline find_syntax_by_file_name() and find_syntax_by_file_name_extension()

There is no benefit to keeping separate functions.
This commit is contained in:
Martin Nordholts 2021-09-15 21:37:58 +02:00
parent a0c363647f
commit 974dec38e3

View File

@ -258,9 +258,14 @@ impl HighlightingAssets {
}
fn get_extension_syntax(&self, file_name: &OsStr) -> Result<Option<SyntaxReferenceInSet>> {
let mut syntax = self.find_syntax_by_file_name(file_name)?;
let mut syntax = self.find_syntax_by_extension(file_name.to_str().unwrap_or_default())?;
if syntax.is_none() {
syntax = self.find_syntax_by_file_name_extension(file_name)?;
syntax = self.find_syntax_by_extension(
Path::new(file_name)
.extension()
.and_then(|x| x.to_str())
.unwrap_or_default(),
)?;
}
if syntax.is_none() {
syntax = try_with_stripped_suffix(file_name, |stripped_file_name| {
@ -270,22 +275,6 @@ impl HighlightingAssets {
Ok(syntax)
}
fn find_syntax_by_file_name(&self, file_name: &OsStr) -> Result<Option<SyntaxReferenceInSet>> {
self.find_syntax_by_extension(file_name.to_str().unwrap_or_default())
}
fn find_syntax_by_file_name_extension(
&self,
file_name: &OsStr,
) -> Result<Option<SyntaxReferenceInSet>> {
self.find_syntax_by_extension(
Path::new(file_name)
.extension()
.and_then(|x| x.to_str())
.unwrap_or_default(),
)
}
fn get_first_line_syntax(
&self,
reader: &mut InputReader,