From eb639eb2e4610ed2b440c8d95217f125005288fd Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Tue, 22 Sep 2020 18:23:48 +0900 Subject: More robust syntax detection/grammar loading. --- helix-term/src/editor.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'helix-term') diff --git a/helix-term/src/editor.rs b/helix-term/src/editor.rs index 790c3f16..24e62306 100644 --- a/helix-term/src/editor.rs +++ b/helix-term/src/editor.rs @@ -1,10 +1,5 @@ use crate::Args; -use helix_core::{ - state::coords_at_pos, - state::Mode, - syntax::{HighlightConfiguration, HighlightEvent, Highlighter}, - State, -}; +use helix_core::{state::coords_at_pos, state::Mode, syntax::HighlightEvent, State}; use helix_view::{commands, keymap, View}; use std::{ @@ -107,14 +102,18 @@ impl Editor { // TODO: cache highlight results // TODO: only recalculate when state.doc is actually modified - let highlights: Vec<_> = view - .state - .syntax - .as_mut() - .unwrap() - .highlight_iter(source_code.as_bytes(), Some(range), None, |_| None) - .unwrap() - .collect(); // TODO: we collect here to avoid double borrow, fix later + let highlights: Vec<_> = match view.state.syntax.as_mut() { + Some(syntax) => { + syntax + .highlight_iter(source_code.as_bytes(), Some(range), None, |_| None) + .unwrap() + .collect() // TODO: we collect here to avoid double borrow, fix later + } + None => vec![Ok(HighlightEvent::Source { + start: range.start, + end: range.end, + })], + }; let mut spans = Vec::new(); -- cgit v1.2.3-70-g09d2