pub struct SourceDocument { /* private fields */ }Expand description
A source document retained independently from canonical semantic nodes.
Whitespace and other non-comment trivia remain in Self::text. Comments
are indexed as a convenience for stable span-based attachment; callers
should use SourceEdit for local changes and reparse the edited text to
obtain updated semantic spans.
Implementations§
Source§impl SourceDocument
impl SourceDocument
Sourcepub fn new(text: impl Into<String>) -> Self
pub fn new(text: impl Into<String>) -> Self
Retain source text and index supported line comments (// ...).
Sourcepub fn comments(&self) -> Iter<'_, SourceComment> ⓘ
pub fn comments(&self) -> Iter<'_, SourceComment> ⓘ
All indexed comments in authored source order.
Sourcepub fn comments_for(&self, span: Span) -> impl Iterator<Item = &SourceComment>
pub fn comments_for(&self, span: Span) -> impl Iterator<Item = &SourceComment>
Comments whose complete source range is inside a semantic span.
This is the attachment rule for the supported slice. Comments outside a node span remain document-level preserved source and are never guessed into a neighboring node.
Sourcepub fn byte_range(&self, span: Span) -> Option<Range<usize>>
pub fn byte_range(&self, span: Span) -> Option<Range<usize>>
Convert a line/column span into a UTF-8 byte range in this document.
Sourcepub fn edit(
&self,
range: Range<usize>,
replacement: impl Into<String>,
) -> Result<SourceEdit, SourceEditError>
pub fn edit( &self, range: Range<usize>, replacement: impl Into<String>, ) -> Result<SourceEdit, SourceEditError>
Create a checked replacement for a UTF-8 byte range.
Sourcepub fn edit_span(
&self,
span: Span,
replacement: impl Into<String>,
) -> Result<SourceEdit, SourceEditError>
pub fn edit_span( &self, span: Span, replacement: impl Into<String>, ) -> Result<SourceEdit, SourceEditError>
Create a checked replacement for a semantic span.
Sourcepub fn apply(&self, edits: &[SourceEdit]) -> Result<Self, SourceEditError>
pub fn apply(&self, edits: &[SourceEdit]) -> Result<Self, SourceEditError>
Apply non-overlapping edits against this exact document.
Trait Implementations§
Source§impl Clone for SourceDocument
impl Clone for SourceDocument
Source§fn clone(&self) -> SourceDocument
fn clone(&self) -> SourceDocument
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more