@@ -768,7 +768,11 @@ fn byte_range_to_str(range: std::ops::Range<usize>, source: RopeSlice) -> Cow<st
768768}
769769
770770impl Syntax {
771− pub fn new(source: &Rope, config: Arc<HighlightConfiguration>, loader: Arc<Loader>) -> Self {
771+ pub fn new(
772+ source: &Rope,
773+ config: Arc<HighlightConfiguration>,
774+ loader: Arc<Loader>,
775+ ) -> Option<Self> {
772776 let root_layer = LanguageLayer {
773777 tree: None,
774778 config,
@@ -793,11 +797,13 @@ impl Syntax {
793797 loader,
794798 };
795799
796− syntax
797− .update(source, source, &ChangeSet::new(source))
798− .unwrap();
800+ let res = syntax.update(source, source, &ChangeSet::new(source));
799801
800− syntax
802+ if res.is_err() {
803+ log::error!("TS parser failed, disabeling TS for the current buffer: {res:?}");
804+ return None;
805+ }
806+ Some(syntax)
801807 }
802808
803809 pub fn update(
@@ -925,6 +931,7 @@ impl Syntax {
925931
926932 PARSER.with(|ts_parser| {
927933 let ts_parser = &mut ts_parser.borrow_mut();
934+ ts_parser.parser.set_timeout_micros(1000 * 500); // half a second is pretty generours
928935 let mut cursor = ts_parser.cursors.pop().unwrap_or_else(QueryCursor::new);
929936 // TODO: might need to set cursor range
930937 cursor.set_byte_range(0..usize::MAX);
@@ -2371,7 +2378,7 @@ mod test {
23712378 let mut cursor = QueryCursor::new();
23722379
23732380 let config = HighlightConfiguration::new(language, "", "", "").unwrap();
2374− let syntax = Syntax::new(&source, Arc::new(config), Arc::new(loader));
2381+ let syntax = Syntax::new(&source, Arc::new(config), Arc::new(loader)).unwrap();
23752382
23762383 let root = syntax.tree().root_node();
23772384 let mut test = |capture, range| {
@@ -2442,7 +2449,7 @@ mod test {
24422449 fn main() {}
24432450 ",
24442451 );
2445− let syntax = Syntax::new(&source, Arc::new(config), Arc::new(loader));
2452+ let syntax = Syntax::new(&source, Arc::new(config), Arc::new(loader)).unwrap();
24462453 let tree = syntax.tree();
24472454 let root = tree.root_node();
24482455 assert_eq!(root.kind(), "source_file");
@@ -2529,7 +2536,7 @@ mod test {
25292536 let language = get_language(language_name).unwrap();
25302537
25312538 let config = HighlightConfiguration::new(language, "", "", "").unwrap();
2532− let syntax = Syntax::new(&source, Arc::new(config), Arc::new(loader));
2539+ let syntax = Syntax::new(&source, Arc::new(config), Arc::new(loader)).unwrap();
25332540
25342541 let root = syntax
25352542 .tree()