diff options
author | Blaž Hrastnik | 2020-09-22 09:23:48 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2020-09-22 09:27:37 +0000 |
commit | eb639eb2e4610ed2b440c8d95217f125005288fd (patch) | |
tree | 3dd5d220287a4927f9dc79689d0e9dacb4021b73 /helix-term/src | |
parent | 2c3b10dbb0f270bc83169d28e4ed665557be70ca (diff) |
More robust syntax detection/grammar loading.
Diffstat (limited to 'helix-term/src')
-rw-r--r-- | helix-term/src/editor.rs | 27 |
1 files changed, 13 insertions, 14 deletions
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(); |