Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injection Query Support #430

Merged
merged 9 commits into from
Jul 11, 2021
Merged
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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() {
Expand All @@ -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,
Expand All @@ -106,6 +108,7 @@ impl EditorView {
surface: &mut Surface,
theme: &Theme,
is_focused: bool,
loader: &syntax::Loader,
) {
let text = doc.text().slice(..);

Expand All @@ -122,8 +125,25 @@ 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();
// Safe because the referenced `HighlightConfiguration` is behind
kirawi marked this conversation as resolved.
Show resolved Hide resolved
// an `Arc` that will never be dropped in this function.
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 {
Expand Down Expand Up @@ -719,7 +739,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,
kirawi marked this conversation as resolved.
Show resolved Hide resolved
);
}

if let Some(info) = std::mem::take(&mut cx.editor.autoinfo) {
Expand Down