pub struct TextContent {
pub location: Option<Range>,
/* private fields */
}Expand description
Represents user-provided text content with source position tracking.
TextContent acts as a facade over different internal representations, allowing the text layer to evolve without breaking the AST structure. Currently stores plain text; future versions will support parsed inline nodes.
Fields§
§location: Option<Range>Location in the source covering this text
Implementations§
Source§impl TextContent
impl TextContent
Sourcepub fn from_string(text: String, location: Option<Range>) -> Self
pub fn from_string(text: String, location: Option<Range>) -> Self
Create TextContent from a string and optional source location.
§Arguments
text- The raw text contentlocation- Optional source location of this text
Sourcepub fn as_string(&self) -> &str
pub fn as_string(&self) -> &str
Get the text content as a string slice.
Works regardless of internal representation. In Phase 1, returns the stored string directly. In Phase 2, would flatten inline nodes to text.
Sourcepub fn as_string_mut(&mut self) -> &mut String
pub fn as_string_mut(&mut self) -> &mut String
Get mutable access to the text content.
Note: Only available in Phase 1. Once inlines are parsed, you would need to reconstruct inlines after mutations.
§Panics
In Phase 2, this may panic or return an error if inlines have been parsed.
Sourcepub fn inline_items(&self) -> InlineContent
pub fn inline_items(&self) -> InlineContent
Parse inline items contained in this text.
Sourcepub fn inline_nodes(&self) -> Option<&[InlineNode]>
pub fn inline_nodes(&self) -> Option<&[InlineNode]>
Returns a reference to parsed inline nodes when available.
Sourcepub fn ensure_inline_parsed(&mut self)
pub fn ensure_inline_parsed(&mut self)
Parse inline nodes (if not already parsed) and store them in this TextContent.
Sourcepub fn inlines(&self) -> Option<&[InlineNode]>
pub fn inlines(&self) -> Option<&[InlineNode]>
Get parsed inline nodes if available (LSP API).
Returns Some if inlines have been parsed via parse_inlines() or inlines_or_parse().
Returns None if content is still in plain text form.
This is a convenience alias for inline_nodes().
Sourcepub fn parse_inlines(&mut self)
pub fn parse_inlines(&mut self)
Parse text into inline nodes and store the result (LSP API).
This method is idempotent - calling it multiple times has no additional effect.
After calling this method, inlines() will return Some.
This is a convenience alias for ensure_inline_parsed().
Sourcepub fn inlines_or_parse(&mut self) -> &[InlineNode]
pub fn inlines_or_parse(&mut self) -> &[InlineNode]
Get or parse inline nodes (LSP API).
If inlines are already parsed, returns a reference to them. Otherwise, parses the text into inlines, stores the result, and returns a reference.
This is the recommended method for LSP features that need access to inline elements.
Trait Implementations§
Source§impl AsRef<str> for TextContent
impl AsRef<str> for TextContent
Source§impl Clone for TextContent
impl Clone for TextContent
Source§fn clone(&self) -> TextContent
fn clone(&self) -> TextContent
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TextContent
impl Debug for TextContent
Source§impl Default for TextContent
impl Default for TextContent
Source§impl From<&str> for TextContent
impl From<&str> for TextContent
Source§impl From<String> for TextContent
impl From<String> for TextContent
Source§impl PartialEq for TextContent
impl PartialEq for TextContent
impl StructuralPartialEq for TextContent
Auto Trait Implementations§
impl Freeze for TextContent
impl RefUnwindSafe for TextContent
impl Send for TextContent
impl Sync for TextContent
impl Unpin for TextContent
impl UnsafeUnpin for TextContent
impl UnwindSafe for TextContent
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§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>
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