pub struct SourceTextInfo { /* private fields */ }
Expand description

Stores the source text along with other data such as where all the lines occur in the text.

Note: This struct is cheap to clone.

Implementations§

source§

impl SourceTextInfo

source

pub fn new(text: Arc<str>) -> SourceTextInfo

Creates a new SourceTextInfo from the provided source text.

source

pub fn new_with_pos(start_pos: SourcePos, text: Arc<str>) -> SourceTextInfo

Creates a new SourceTextInfo from the provided source start position and source text.

Note: When bundling swc will keep increasing the start position for each source file.

source

pub fn new_with_indent_width( start_pos: SourcePos, text: Arc<str>, indent_width: usize ) -> SourceTextInfo

Creates a new SourceTextInfo from the provided start position, source text, and indentation width.

The indentation width determines the number of columns to use when going over a tab character. For example, an indent width of 2 will mean each tab character will represent 2 columns. The default indentation width used in the other methods is 2 to match the default indentation used by deno fmt.

source

pub fn from_string(text: String) -> SourceTextInfo

Creates a new SourceTextInfo from the provided source text.

Generally, prefer using SourceTextInfo::new to provide a string already in an std::sync::Arc.

source

pub fn as_string_input(&self) -> StringInput<'_>

Gets an swc StringInput for this text information that can be used with parsing.

source

pub fn text(&self) -> Arc<str>

Gets the source text.

source

pub fn text_str(&self) -> &str

Gets a reference to the source text.

source

pub fn range(&self) -> SourceRange<StartSourcePos>

Gets the range—start and end byte position—of the source text.

source

pub fn lines_count(&self) -> usize

Gets the number of lines in the source text.

source

pub fn line_index(&self, pos: SourcePos) -> usize

Gets the 0-indexed line index at the provided byte position.

Note that this will panic when providing a byte position outside the range of the source text.

source

pub fn line_start(&self, line_index: usize) -> SourcePos

Gets the line start byte position of the provided 0-indexed line index.

Note that this will panic if providing a line index outside the bounds of the number of lines.

source

pub fn line_end(&self, line_index: usize) -> SourcePos

Gets the line end byte position of the provided 0-indexed line index.

Note that this will panic if providing a line index outside the bounds of the number of lines.

source

pub fn line_and_column_index(&self, pos: SourcePos) -> LineAndColumnIndex

Gets the 0-indexed line and column index of the provided byte position.

Note that this will panic when providing a byte position outside the range of the source text.

source

pub fn line_and_column_display(&self, pos: SourcePos) -> LineAndColumnDisplay

Gets the 1-indexed line and column index of the provided byte position taking into account the default indentation width.

Note that this will panic when providing a byte position outside the range of the source text.

source

pub fn line_and_column_display_with_indent_width( &self, pos: SourcePos, indent_width: usize ) -> LineAndColumnDisplay

Gets the 1-indexed line and column index of the provided byte position with a custom indentation width.

Note that this will panic when providing a byte position outside the range of the source text.

source

pub fn loc_to_source_pos( &self, line_and_column_index: LineAndColumnIndex ) -> SourcePos

Gets the source position of the provided line and column index.

Note that this will panic if providing a line index outside the bounds of the number of lines, but will clip the the line end byte index when exceeding the line length.

source

pub fn line_text(&self, line_index: usize) -> &str

Gets a reference to the text slice of the line at the provided 0-based index.

Note that this will panic if providing a line index outside the bounds of the number of lines.

source

pub fn range_text(&self, range: &SourceRange) -> &str

Gets the source text located within the provided range.

Trait Implementations§

source§

impl Clone for SourceTextInfo

source§

fn clone(&self) -> SourceTextInfo

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for SourceTextInfo

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'a> SourceTextInfoProvider<'a> for &'a SourceTextInfo

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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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
source§

impl<T> Send for T
where T: ?Sized,

source§

impl<T> Sync for T
where T: ?Sized,