summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-06-28 22:00:47 -0400
committerDan Davison <dandavison7@gmail.com>2020-06-30 08:00:30 -0400
commitf5c7053fdbedebb512151346a7eefd2b7d3565c9 (patch)
treeb1f9320ac0a7640f4d117bfede54712ceef797b3
parentdb25d92cba169359b8cd2bb315742a6d36a0a3dd (diff)
Fix infinite recursion when there are no syntax references
-rw-r--r--src/paint.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/paint.rs b/src/paint.rs
index c5451ead..0df02b2a 100644
--- a/src/paint.rs
+++ b/src/paint.rs
@@ -7,7 +7,7 @@ use syntect::easy::HighlightLines;
use syntect::highlighting::Style as SyntectStyle;
use syntect::parsing::{SyntaxReference, SyntaxSet};
-use crate::config;
+use crate::config::{self, delta_unreachable};
use crate::delta::State;
use crate::edits;
use crate::features::line_numbers;
@@ -53,9 +53,16 @@ impl<'a> Painter<'a> {
}
fn get_syntax(syntax_set: &'a SyntaxSet, extension: Option<&str>) -> &'a SyntaxReference {
- syntax_set
- .find_syntax_by_extension(extension.unwrap_or("txt"))
- .unwrap_or_else(|| Painter::get_syntax(syntax_set, Some("txt")))
+ if let Some(extension) = extension {
+ if let Some(syntax) = syntax_set.find_syntax_by_extension(extension) {
+ return syntax;
+ }
+ }
+ return syntax_set
+ .find_syntax_by_extension("txt")
+ .unwrap_or_else(|| {
+ delta_unreachable("Failed to find any language syntax definitions.")
+ });
}
pub fn set_highlighter(&mut self) {