aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorKirawi2021-07-11 01:40:18 +0000
committerGitHub2021-07-11 01:40:18 +0000
commitbb121a3e4b97efef1380414f33361404900d6f72 (patch)
treea1fa6fb42c2ea97d8a3bcdda4a8ba610d6e6f806 /helix-term/src
parent084a8a952292521f1f7b7f4144e6823c29b85507 (diff)
Injection Query Support (#430)
* wip * wip * fixed unsafe * fix clippy * move out reference variable * fmt * remove arc * change safety comment
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/ui/editor.rs36
1 files changed, 33 insertions, 3 deletions
diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs
index ef13004c..9a2fbf57 100644
--- a/helix-term/src/ui/editor.rs
+++ b/helix-term/src/ui/editor.rs
@@ -64,6 +64,7 @@ impl EditorView {
surface: &mut Surface,
theme: &Theme,
is_focused: bool,
+ loader: &syntax::Loader,
) {
let area = Rect::new(
view.area.x + OFFSET,
@@ -72,7 +73,7 @@ impl EditorView {
view.area.height.saturating_sub(1),
); // - 1 for statusline
- self.render_buffer(doc, view, area, surface, theme, is_focused);
+ self.render_buffer(doc, view, area, surface, theme, is_focused, loader);
// if we're not at the edge of the screen, draw a right border
if viewport.right() != view.area.right() {
@@ -98,6 +99,7 @@ impl EditorView {
self.render_statusline(doc, view, area, surface, theme, is_focused);
}
+ #[allow(clippy::too_many_arguments)]
pub fn render_buffer(
&self,
doc: &Document,
@@ -106,6 +108,7 @@ impl EditorView {
surface: &mut Surface,
theme: &Theme,
is_focused: bool,
+ loader: &syntax::Loader,
) {
let text = doc.text().slice(..);
@@ -122,8 +125,26 @@ 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, |_| None)
+ .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();
+ // SAFETY: the referenced `HighlightConfiguration` behind
+ // the `Arc` is guaranteed to remain valid throughout the
+ // duration of the highlight.
+ let config_ref = unsafe {
+ std::mem::transmute::<
+ _,
+ &'static syntax::HighlightConfiguration,
+ >(config_ref)
+ };
+ Some(config_ref)
+ })
+ })
.collect() // TODO: we collect here to avoid holding the lock, fix later
}
None => vec![Ok(HighlightEvent::Source {
@@ -719,7 +740,16 @@ impl Component for EditorView {
for (view, is_focused) in cx.editor.tree.views() {
let doc = cx.editor.document(view.doc).unwrap();
- self.render_view(doc, view, area, surface, &cx.editor.theme, is_focused);
+ let loader = &cx.editor.syn_loader;
+ self.render_view(
+ doc,
+ view,
+ area,
+ surface,
+ &cx.editor.theme,
+ is_focused,
+ loader,
+ );
}
if let Some(info) = std::mem::take(&mut cx.editor.autoinfo) {