pub struct DecorationCtx<'a> {
pub buffer_id: BufferId,
/* private fields */
}Expand description
Read-only context passed to crate::Mode::gutter_decorations.
Dependency inversion: the renderer builds a per-pane
ServiceRegistry of typed render-state snapshots (diff sign map, LSP
diagnostics, CompilationSeverityData, BuiltinSignIds, …) and
each mode pulls only the data it knows about through
service. The renderer therefore never depends on the
crate that owns a mode, and a mode never sees another mode’s data.
Built once per pane per frame, on the render path: a
gutter_decorations implementation must do nothing heavier than a map
over data already computed off-thread.
§Examples
use lattice_core::BufferId;
use lattice_mode::{DecorationCtx, ServiceRegistry};
struct MyMarks(Vec<u32>);
let mut services = ServiceRegistry::new();
services.register(MyMarks(vec![3, 7]));
let ctx = DecorationCtx::new(BufferId(1), &services);
assert_eq!(ctx.service::<MyMarks>().unwrap().0, vec![3, 7]);
// A snapshot nobody injected is simply absent: contribute nothing.
assert!(ctx.service::<String>().is_none());Fields§
§buffer_id: BufferIdThe buffer shown in the pane being decorated.
Implementations§
Source§impl<'a> DecorationCtx<'a>
impl<'a> DecorationCtx<'a>
Sourcepub fn new(buffer_id: BufferId, services: &'a ServiceRegistry) -> Self
pub fn new(buffer_id: BufferId, services: &'a ServiceRegistry) -> Self
Build a context over services for the pane showing buffer_id.
Called by the renderers, not by modes.
Sourcepub fn service<T: Any + Send + Sync>(&self) -> Option<Arc<T>>
pub fn service<T: Any + Send + Sync>(&self) -> Option<Arc<T>>
Typed lookup of a render-state snapshot the renderer injected.
None when nothing of type T was registered for this frame — a
stripped render path or data not yet produced — and the mode should
then contribute nothing rather than fail. Same TypeId rule as
ServiceRegistry::get: look up with exactly the registered type.