Skip to content

Commit

Permalink
move out reference variable
Browse files Browse the repository at this point in the history
  • Loading branch information
kirawi committed Jul 9, 2021
1 parent 7eed664 commit 5704ae0
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,36 +123,35 @@ impl EditorView {
};

// TODO: range doesn't actually restrict source, just highlight range
let highlights: Vec<_> = match doc.syntax() {
Some(syntax) => {
let scopes = theme.scopes();
syntax
.highlight_iter(text.slice(..), Some(range), None, |language| {
loader
.language_config_for_scope(&format!("source.{}", language))
.and_then(|language_config| {
let config = language_config.highlight_config(scopes)?;
let config_ref = {
let reference = config.as_ref();
let highlights: Vec<_> =
match doc.syntax() {
Some(syntax) => {
let scopes = theme.scopes();
syntax
.highlight_iter(text.slice(..), Some(range), None, |language| {
loader
.language_config_for_scope(&format!("source.{}", language))
.and_then(|language_config| {
let config = language_config.highlight_config(scopes)?;
let config_ref = config.as_ref();
// Safe because the referenced `HighglightConfiguration` is behind
// an `Arc` that will never be dropped in this function.
unsafe {
let config_ref = unsafe {
std::mem::transmute::<
_,
&'static syntax::HighlightConfiguration,
>(reference)
}
};
Some(config_ref)
})
})
.collect() // TODO: we collect here to avoid holding the lock, fix later
}
None => vec![Ok(HighlightEvent::Source {
start: range.start,
end: range.end,
})],
};
>(config_ref)
};
Some(config_ref)
})
})
.collect() // TODO: we collect here to avoid holding the lock, fix later
}
None => vec![Ok(HighlightEvent::Source {
start: range.start,
end: range.end,
})],
};
let mut spans = Vec::new();
let mut visual_x = 0u16;
let mut line = 0u16;
Expand Down

0 comments on commit 5704ae0

Please sign in to comment.