mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-25 19:03:30 +04:00
Injection Query Support (#430)
* wip * wip * fixed unsafe * fix clippy * move out reference variable * fmt * remove arc * change safety comment
This commit is contained in:
parent
084a8a9522
commit
bb121a3e4b
@ -64,6 +64,7 @@ pub fn render_view(
|
|||||||
surface: &mut Surface,
|
surface: &mut Surface,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
is_focused: bool,
|
is_focused: bool,
|
||||||
|
loader: &syntax::Loader,
|
||||||
) {
|
) {
|
||||||
let area = Rect::new(
|
let area = Rect::new(
|
||||||
view.area.x + OFFSET,
|
view.area.x + OFFSET,
|
||||||
@ -72,7 +73,7 @@ pub fn render_view(
|
|||||||
view.area.height.saturating_sub(1),
|
view.area.height.saturating_sub(1),
|
||||||
); // - 1 for statusline
|
); // - 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 we're not at the edge of the screen, draw a right border
|
||||||
if viewport.right() != view.area.right() {
|
if viewport.right() != view.area.right() {
|
||||||
@ -98,6 +99,7 @@ pub fn render_view(
|
|||||||
self.render_statusline(doc, view, area, surface, theme, is_focused);
|
self.render_statusline(doc, view, area, surface, theme, is_focused);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn render_buffer(
|
pub fn render_buffer(
|
||||||
&self,
|
&self,
|
||||||
doc: &Document,
|
doc: &Document,
|
||||||
@ -106,6 +108,7 @@ pub fn render_buffer(
|
|||||||
surface: &mut Surface,
|
surface: &mut Surface,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
is_focused: bool,
|
is_focused: bool,
|
||||||
|
loader: &syntax::Loader,
|
||||||
) {
|
) {
|
||||||
let text = doc.text().slice(..);
|
let text = doc.text().slice(..);
|
||||||
|
|
||||||
@ -122,8 +125,26 @@ pub fn render_buffer(
|
|||||||
// TODO: range doesn't actually restrict source, just highlight range
|
// TODO: range doesn't actually restrict source, just highlight range
|
||||||
let highlights: Vec<_> = match doc.syntax() {
|
let highlights: Vec<_> = match doc.syntax() {
|
||||||
Some(syntax) => {
|
Some(syntax) => {
|
||||||
|
let scopes = theme.scopes();
|
||||||
syntax
|
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
|
.collect() // TODO: we collect here to avoid holding the lock, fix later
|
||||||
}
|
}
|
||||||
None => vec![Ok(HighlightEvent::Source {
|
None => vec![Ok(HighlightEvent::Source {
|
||||||
@ -719,7 +740,16 @@ fn render(&self, area: Rect, surface: &mut Surface, cx: &mut Context) {
|
|||||||
|
|
||||||
for (view, is_focused) in cx.editor.tree.views() {
|
for (view, is_focused) in cx.editor.tree.views() {
|
||||||
let doc = cx.editor.document(view.doc).unwrap();
|
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) {
|
if let Some(info) = std::mem::take(&mut cx.editor.autoinfo) {
|
||||||
|
Loading…
Reference in New Issue
Block a user