mirror of
https://github.com/sharkdp/bat.git
synced 2025-09-15 01:32:25 +01:00
HighlightingAssets: Make .syntaxes() and syntax_for_file_name() failable
Or rather, introduce new versions of these methods and deprecate the old ones. This is preparation to enable robust and user-friendly support for lazy-loading. With lazy-loading, we don't know if the SyntaxSet is valid until after we try to use it, so wherever we try to use it, we need to return a Result. See discussion about panics in #1747.
This commit is contained in:
@@ -174,7 +174,7 @@ impl<'a> InteractivePrinter<'a> {
|
||||
let syntax = match assets.get_syntax(config.language, input, &config.syntax_mapping) {
|
||||
Ok(syntax) => syntax,
|
||||
Err(Error(ErrorKind::UndetectedSyntax(_), _)) => {
|
||||
assets.get_syntax_set().find_syntax_plain_text()
|
||||
assets.get_syntax_set()?.find_syntax_plain_text()
|
||||
}
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
@@ -192,7 +192,7 @@ impl<'a> InteractivePrinter<'a> {
|
||||
#[cfg(feature = "git")]
|
||||
line_changes,
|
||||
highlighter,
|
||||
syntax_set: assets.get_syntax_set(),
|
||||
syntax_set: assets.get_syntax_set()?,
|
||||
background_color_highlight,
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user