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
impl DocSync
Sourcepub fn new() -> Self
pub fn new() -> Self
Empty state. Use Self::open to bring a buffer under
management.
Sourcepub fn open(
&mut self,
uri: Uri,
language_id: impl Into<String>,
text: impl Into<String>,
) -> DidOpenTextDocumentParams
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.
Sourcepub fn record_edit(
&mut self,
capabilities: &Capabilities,
uri: &Uri,
edit: &Edit,
) -> LspResult<()>
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.
Sourcepub fn take_flush_payload(
&mut self,
capabilities: &Capabilities,
uri: &Uri,
) -> Option<DidChangeTextDocumentParams>
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; returnsNone(caller skips the wire).
Sourcepub fn take_flush_all_payloads(
&mut self,
capabilities: &Capabilities,
) -> Vec<(Uri, DidChangeTextDocumentParams)>
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.
Sourcepub fn close(
&mut self,
capabilities: &Capabilities,
uri: &Uri,
) -> Option<ClosePayloads>
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.
Sourcepub fn is_open(&self, uri: &Uri) -> bool
pub fn is_open(&self, uri: &Uri) -> bool
True iff the URI is currently open under this DocSync.
Sourcepub fn version(&self, uri: &Uri) -> Option<i32>
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).
Sourcepub fn has_pending(&self, uri: &Uri) -> bool
pub fn has_pending(&self, uri: &Uri) -> bool
True iff at least one queued change exists for uri.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for DocSync
impl Freeze for DocSync
impl Send for DocSync
impl Sync for DocSync
impl Unpin for DocSync
impl UnsafeUnpin for DocSync
impl UnwindSafe for DocSync
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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