pub struct Document { /* private fields */ }Expand description
An open document backed by a rope data structure for efficient incremental edits.
This is the primary representation for documents being actively edited in an LSP context, where frequent small edits need to be applied efficiently.
Implementations§
Source§impl Document
impl Document
Sourcepub fn new(text: &str, language_id: String) -> Self
pub fn new(text: &str, language_id: String) -> Self
Create a new document from the full text content.
Sourcepub fn apply_edit(&mut self, start_byte: usize, end_byte: usize, new_text: &str)
pub fn apply_edit(&mut self, start_byte: usize, end_byte: usize, new_text: &str)
Apply an incremental edit to the document.
start_byte and end_byte define the range to replace.
If they are equal, this is an insertion. If new_text is empty,
this is a deletion.
Sourcepub fn apply_edit_lc(
&mut self,
start_line: usize,
start_col: usize,
end_line: usize,
end_col: usize,
new_text: &str,
)
pub fn apply_edit_lc( &mut self, start_line: usize, start_col: usize, end_line: usize, end_col: usize, new_text: &str, )
Apply an edit using line/column (0-based) coordinates.
Sourcepub fn set_content(&mut self, text: &str)
pub fn set_content(&mut self, text: &str)
Replace the entire content (full sync).
Sourcepub fn slice_bytes(&self, start: usize, end: usize) -> String
pub fn slice_bytes(&self, start: usize, end: usize) -> String
Get a slice of text by byte range.
Sourcepub fn byte_to_line_col(&self, byte_offset: usize) -> (usize, usize)
pub fn byte_to_line_col(&self, byte_offset: usize) -> (usize, usize)
Convert a byte offset to (line, column) (0-based).
Sourcepub fn line_col_to_byte(&self, line: usize, col: usize) -> usize
pub fn line_col_to_byte(&self, line: usize, col: usize) -> usize
Convert (line, column) (0-based) to a byte offset.
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Number of lines in the document.
Sourcepub fn language_id(&self) -> &str
pub fn language_id(&self) -> &str
The document’s language ID.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnsafeUnpin for Document
impl UnwindSafe for Document
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
Source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
Query the “status” flags for the
self file descriptor.Source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
Source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
Set the “status” flags for the
self file descriptor. Read moreSource§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> 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>
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 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>
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