pub struct SourceEditIndex { /* private fields */ }Expand description
The export statements and the class and enum members of one file text.
Implementations§
Source§impl SourceEditIndex
impl SourceEditIndex
Sourcepub fn parse(path: &Path, source: &str) -> Option<SourceEditIndex>
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.
Sourcepub fn export_statement(
&self,
name: &str,
line: u32,
col: u32,
) -> Result<&ExportStatement, EditRefusal>
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.
Sourcepub fn statements(&self) -> &[ExportStatement]
pub fn statements(&self) -> &[ExportStatement]
Each export statement of the file, in source order.
Sourcepub fn export_statements_on_line(
&self,
line: u32,
) -> impl Iterator<Item = &ExportStatement>
pub fn export_statements_on_line( &self, line: u32, ) -> impl Iterator<Item = &ExportStatement>
The statements whose export keyword is on the 1-based line.
Sourcepub fn members_on_line(&self, line: u32) -> impl Iterator<Item = &MemberSpan>
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.
Sourcepub fn members(&self) -> &[MemberSpan]
pub fn members(&self) -> &[MemberSpan]
Each class element and enum member of the file. The elements of one class body or enum body are in source order, and each body comes before the members nested inside it.
Sourcepub fn enums_named<'s>(
&'s self,
name: &'s str,
) -> impl Iterator<Item = &'s EnumSpans>
pub fn enums_named<'s>( &'s self, name: &'s str, ) -> impl Iterator<Item = &'s EnumSpans>
The enum declarations named name, at each depth.
Sourcepub fn remove_enum_members(
&self,
name: &str,
members: &[&str],
line: u32,
) -> Result<Vec<SpanEdit>, EditRefusal>
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.
Sourcepub fn enum_on_line(&self, name: &str, line: u32) -> Option<&EnumSpans>
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.
Sourcepub fn statement_at(&self, start: u32) -> Option<&ExportStatement>
pub fn statement_at(&self, start: u32) -> Option<&ExportStatement>
The statement whose export keyword is at byte start.
Sourcepub fn line_range(&self, start: u32, end: u32) -> (usize, usize)
pub fn line_range(&self, start: u32, end: u32) -> (usize, usize)
The 0-based first and last line of the bytes start..end.
Sourcepub fn owns_its_lines(&self, start: u32, end: u32) -> bool
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§
impl Forget for SourceEditIndex
impl Freeze for SourceEditIndex
impl Move for SourceEditIndex
impl RefUnwindSafe for SourceEditIndex
impl Send for SourceEditIndex
impl Sync for SourceEditIndex
impl Unpin for SourceEditIndex
impl UnsafeUnpin for SourceEditIndex
impl UnwindSafe for SourceEditIndex
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
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