Skip to main content

DocSync

Struct DocSync 

Source
pub struct DocSync { /* private fields */ }
Expand description

Per-actor document-sync state. Pure state + pure methods – no I/O, no ServerHandle dependency. The owning actor sends the LSP params returned by open / take_flush_payload / close over the wire via its writer task.

Mutating methods either update the mirror in place or return the LSP params the caller must ship. record_edit and the flush helpers take &Capabilities so the position-encoding converter knows whether to walk utf-16 columns; pre-this- refactor it pulled the encoding off a ServerHandle borrow.

Implementations§

Source§

impl DocSync

Source

pub fn new() -> Self

Empty state. Use Self::open to bring a buffer under management.

Source

pub fn open( &mut self, uri: Uri, language_id: impl Into<String>, text: impl Into<String>, ) -> DidOpenTextDocumentParams

Bring a buffer under management with language_id and initial text. Returns the didOpen params the caller ships over the wire. Pure: state mutation + payload construction, no I/O.

Source

pub fn record_edit( &mut self, capabilities: &Capabilities, uri: &Uri, edit: &Edit, ) -> LspResult<()>

Record one committed edit. Updates the mirror, builds the LSP change event for queued send, and bumps the version. Does NOT produce a flush payload – the caller drains via Self::take_flush_payload when ready (debounced or eager). Returns Err only when the URI isn’t open or the edit’s range falls outside the mirror.

Source

pub fn take_flush_payload( &mut self, capabilities: &Capabilities, uri: &Uri, ) -> Option<DidChangeTextDocumentParams>

Drain queued change events into a didChange payload. Returns None when the queue is empty (no-op flush) or the URI isn’t open. Honours the negotiated sync mode:

  • Incremental: payload contains the queued events verbatim.
  • Full: payload is one synthetic change carrying the entire post-edit mirror text (LSP convention for full sync).
  • None: pending is cleared; returns None (caller skips the wire).
Source

pub fn take_flush_all_payloads( &mut self, capabilities: &Capabilities, ) -> Vec<(Uri, DidChangeTextDocumentParams)>

Drain every open doc’s pending changes into per-URI didChange payloads. Used by the actor’s debounce timer + by editor shutdown so the server sees a coherent final state before didClose.

Source

pub fn close( &mut self, capabilities: &Capabilities, uri: &Uri, ) -> Option<ClosePayloads>

Drop the mirror for uri and return the didClose payload (paired with any final flush payload the actor should send first). Returns None when the URI wasn’t open. The actor sends the optional final_changes followed by the close notification so the server’s last view of the doc matches the editor’s.

Source

pub fn is_open(&self, uri: &Uri) -> bool

True iff the URI is currently open under this DocSync.

Source

pub fn version(&self, uri: &Uri) -> Option<i32>

The version we’ll attach to the next didChange for uri if no further edits land before flush. Used by tests + diagnostics gating (drop diagnostics older than our version).

Source

pub fn has_pending(&self, uri: &Uri) -> bool

True iff at least one queued change exists for uri.

Trait Implementations§

Source§

impl Default for DocSync

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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