Skip to main content

SourceMap

Struct SourceMap 

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

Source map: the main data structure mapping source positions to AST nodes.

Supports IDE features such as hover, go-to-definition, semantic highlighting, and reference lookup.

Implementations§

Source§

impl SourceMap

Source

pub fn new(source: &str) -> Self

Create a new, empty source map for the given source text.

Source

pub fn source(&self) -> &str

Get the original source text.

Source

pub fn entries(&self) -> &[SourceEntry]

Get all entries.

Source

pub fn line_count(&self) -> usize

Return the total number of lines in the source.

Source

pub fn offset_to_position(&self, offset: usize) -> (usize, usize)

Convert a byte offset to a (line, column) pair.

Lines and columns are 1-indexed, matching the convention in Span.

Source

pub fn position_to_offset(&self, line: usize, col: usize) -> usize

Convert a (line, column) pair to a byte offset.

Lines and columns are 1-indexed.

Source

pub fn line_content(&self, line: usize) -> &str

Get the text content of a specific line (1-indexed).

Source

pub fn entry_at(&self, line: usize, col: usize) -> Option<&SourceEntry>

Find the entry at a given (line, column) position (1-indexed).

Source

pub fn entries_in_range(&self, start: &Span, end: &Span) -> Vec<&SourceEntry>

Find all entries whose spans overlap with the given range.

Source

pub fn definitions(&self) -> Vec<&SourceEntry>

Get all definition entries.

Source

pub fn references_to(&self, name: &str) -> Vec<&SourceEntry>

Get all references to a given name.

Source

pub fn entries_of_kind(&self, kind: &EntryKind) -> Vec<&SourceEntry>

Get all entries with the given kind.

Source

pub fn hover_info(&self, line: usize, col: usize) -> Option<HoverInfo>

Produce hover information for a given (line, column) position.

Source

pub fn semantic_tokens(&self) -> Vec<SemanticToken>

Produce all semantic tokens for the source map.

Source

pub fn span_text(&self, span: &Span) -> &str

Get the text corresponding to a span.

Source

pub fn go_to_definition(&self, line: usize, col: usize) -> Option<Span>

Find the definition of a name and return its span.

Source

pub fn find_all_occurrences(&self, line: usize, col: usize) -> Vec<&SourceEntry>

Find all occurrences (definitions + references) of a name at position.

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.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

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.