Skip to main content

PendingSyntheticHighlights

Struct PendingSyntheticHighlights 

Source
pub struct PendingSyntheticHighlights {
    pub map: Arc<Mutex<HashMap<BufferId, HighlightsUpdate>>>,
    pub waker: Arc<Mutex<Option<Arc<Notify>>>>,
}
Expand description

Shared state between async refresh tasks and the Editor’s tick drain.

The host registers the bare type, so reach it as ctx.service::<PendingSyntheticHighlights>() — which already returns an Arc, i.e. a PendingSyntheticHighlightsHandle to keep. Looking it up as the handle type misses (the ServiceRegistry TypeId rule). Every *_and_wake method fires the editor’s async_landed notify, so the spans reach the screen without a keystroke (the inbound-wake rule).

One pending update per buffer. The map holds the latest undrained update; a second store for the same buffer before the drain runs replaces the first. Two splices in quick succession therefore need a drain between them, or a Replace instead.

§Examples

use std::sync::Arc;
use lattice_core::BufferId;
use lattice_mode::{HighlightsOp, PendingSyntheticHighlights};

let pending = PendingSyntheticHighlights::new();
let wake = Arc::new(tokio::sync::Notify::new());
*pending.waker.lock().unwrap() = Some(wake.clone()); // the host does this at boot

pending.remove_at_and_wake(BufferId(3), 10, 2);
let update = pending.map.lock().unwrap().remove(&BufferId(3)).unwrap();
assert!(matches!(update.op, HighlightsOp::RemoveAt { start_line: 10, count: 2 }));

Fields§

§map: Arc<Mutex<HashMap<BufferId, HighlightsUpdate>>>

Undrained updates by buffer; the host’s tick drain empties it.

§waker: Arc<Mutex<Option<Arc<Notify>>>>

The editor’s async_landed notify, installed by the host at boot. None (a test harness) means stores land but nothing wakes.

Implementations§

Source§

impl PendingSyntheticHighlights

Source

pub fn new() -> Self

Empty map, no waker installed.

Source

pub fn store_and_wake(&self, buffer_id: BufferId, spans: Vec<Vec<StyledSpan>>)

Store per-line spans for buffer_id and fire the waker so the Editor drains them on the next tick. Replaces any existing highlights for the buffer.

Source

pub fn store_refined_and_wake( &self, buffer_id: BufferId, spans: Vec<Vec<StyledSpan>>, refine: Vec<Vec<RefineSpan>>, )

As Self::store_and_wake, carrying intra-line refinement alongside the spans so both shift together (DR.3).

Source

pub fn insert_at_and_wake( &self, buffer_id: BufferId, start_line: u32, spans: Vec<Vec<StyledSpan>>, )

Store per-line spans to be SPLICED IN to existing highlights at a given line offset — lines before start_line keep their spans; spans becomes the new content at start_line; every line that was already at or after start_line shifts DOWN by spans.len(). Use when the underlying text edit INSERTED spans.len() new lines at start_line (e.g. toggle-diff expanding inline content) — the highlight vector must grow and shift in lockstep with the text, or every line after the insertion point ends up painted with the wrong span.

Source

pub fn insert_at_refined_and_wake( &self, buffer_id: BufferId, start_line: u32, spans: Vec<Vec<StyledSpan>>, refine: Vec<Vec<RefineSpan>>, )

Splice spans AND refinement at the same offset (DR.3).

The = toggle inserts an expansion’s lines mid-buffer; both lists must shift by the same amount or the refinement ends up over the wrong rows. Carrying them in one update and splicing them with one implementation is what makes that impossible.

Source

pub fn remove_at_and_wake( &self, buffer_id: BufferId, start_line: u32, count: usize, )

Remove count lines of highlights starting at start_line, shifting everything after them UP by count. The exact inverse of Self::insert_at_and_wake — use when the underlying text edit DELETED count lines at start_line (e.g. toggle-diff collapsing inline content back down).

Source

pub fn wake(&self)

Fire the waker without storing anything. Use when the buffer was modified by a non-refresh action (e.g. toggle-diff) and the existing ExtraHighlights are still valid — the Editor needs to repaint.

Trait Implementations§

Source§

impl Default for PendingSyntheticHighlights

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more