mirror of
https://github.com/sharkdp/bat
synced 2024-11-15 00:27:10 +00:00
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:
parent
a0c363647f
commit
974dec38e3
1 changed files with 7 additions and 18 deletions
|
@ -258,9 +258,14 @@ impl HighlightingAssets {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_extension_syntax(&self, file_name: &OsStr) -> Result<Option<SyntaxReferenceInSet>> {
|
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() {
|
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() {
|
if syntax.is_none() {
|
||||||
syntax = try_with_stripped_suffix(file_name, |stripped_file_name| {
|
syntax = try_with_stripped_suffix(file_name, |stripped_file_name| {
|
||||||
|
@ -270,22 +275,6 @@ impl HighlightingAssets {
|
||||||
Ok(syntax)
|
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(
|
fn get_first_line_syntax(
|
||||||
&self,
|
&self,
|
||||||
reader: &mut InputReader,
|
reader: &mut InputReader,
|
||||||
|
|
Loading…
Reference in a new issue