Skip to main content

SourceEditIndex

Struct SourceEditIndex 

Source
pub struct SourceEditIndex { /* private fields */ }
Expand description

The export statements and the class and enum members of one file text.

Implementations§

Source§

impl SourceEditIndex

Source

pub fn parse(path: &Path, source: &str) -> Option<SourceEditIndex>

Parse source, the text of the file at path.

A JavaScript or TypeScript file is parsed as a whole. A Vue or Svelte file is parsed per inline <script> block and an Astro file per frontmatter block. Each offset is an offset into source.

Returns None for a file type that the engine does not parse here, or when a block does not parse without an error.

Source

pub fn export_statement( &self, name: &str, line: u32, col: u32, ) -> Result<&ExportStatement, EditRefusal>

The statement that exports name on the 1-based line.

col is the 0-based byte column of the name. It decides only between two statements on one line that both export name.

§Errors

EditRefusal::NameNotFound when no statement of the line exports name, and EditRefusal::Ambiguous when the column does not select one of several such statements.

Source

pub fn statements(&self) -> &[ExportStatement]

Each export statement of the file, in source order.

Source

pub fn export_statements_on_line( &self, line: u32, ) -> impl Iterator<Item = &ExportStatement>

The statements whose export keyword is on the 1-based line.

Source

pub fn members_on_line(&self, line: u32) -> impl Iterator<Item = &MemberSpan>

The class elements and enum members whose first byte is on the 1-based line, at each depth of the file.

Source

pub fn enums_named<'s>( &'s self, name: &'s str, ) -> impl Iterator<Item = &'s EnumSpans>

The enum declarations named name, at each depth.

Source

pub fn remove_enum_members( &self, name: &str, members: &[&str], line: u32, ) -> Result<Vec<SpanEdit>, EditRefusal>

The edits that remove members from the enum name. The 1-based line of one member selects the enum when more than one has the name.

A member that owns its lines is deleted with its lines, also an initializer over several lines. A member that shares a line with another member is deleted with one separating comma, and each other byte of the enum stays as it is. A kept member without an initializer that follows a removed member gets an initializer with its old value, as in Medium = 1, so each kept member keeps its value.

§Errors

EditRefusal::NameNotFound when no complete enum of the name has each member, EditRefusal::Ambiguous when line does not select one enum, or when two edits overlap, and EditRefusal::UnknownValue when a kept member needs an initializer and its old value is not a known integer.

Source

pub fn enum_on_line(&self, name: &str, line: u32) -> Option<&EnumSpans>

The enum named name whose declaration covers the 1-based line, when exactly one does.

Source

pub fn statement_at(&self, start: u32) -> Option<&ExportStatement>

The statement whose export keyword is at byte start.

Source

pub fn line_range(&self, start: u32, end: u32) -> (usize, usize)

The 0-based first and last line of the bytes start..end.

Source

pub fn owns_its_lines(&self, start: u32, end: u32) -> bool

True when no other text shares the lines of start..end: only white space is before start on its line, and only white space and ; are after end on its line.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'a, T> FromIn<'a, T> for T

Source§

fn from_in(t: T, _: &'a Allocator) -> T

Converts to this type from the input type within the given allocator.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

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

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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

impl<'a, T, U> IntoIn<'a, U> for T
where U: FromIn<'a, T>,

Source§

fn into_in(self, allocator: &'a Allocator) -> U

Converts this type into the (usually inferred) input type within the given allocator.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.
Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more