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
impl SourceMap
Sourcepub fn entries(&self) -> &[SourceEntry]
pub fn entries(&self) -> &[SourceEntry]
Get all entries.
Sourcepub fn line_count(&self) -> usize
pub fn line_count(&self) -> usize
Return the total number of lines in the source.
Sourcepub fn offset_to_position(&self, offset: usize) -> (usize, usize)
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.
Sourcepub fn position_to_offset(&self, line: usize, col: usize) -> usize
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.
Sourcepub fn line_content(&self, line: usize) -> &str
pub fn line_content(&self, line: usize) -> &str
Get the text content of a specific line (1-indexed).
Sourcepub fn entry_at(&self, line: usize, col: usize) -> Option<&SourceEntry>
pub fn entry_at(&self, line: usize, col: usize) -> Option<&SourceEntry>
Find the entry at a given (line, column) position (1-indexed).
Sourcepub fn entries_in_range(&self, start: &Span, end: &Span) -> Vec<&SourceEntry>
pub fn entries_in_range(&self, start: &Span, end: &Span) -> Vec<&SourceEntry>
Find all entries whose spans overlap with the given range.
Sourcepub fn definitions(&self) -> Vec<&SourceEntry>
pub fn definitions(&self) -> Vec<&SourceEntry>
Get all definition entries.
Sourcepub fn references_to(&self, name: &str) -> Vec<&SourceEntry>
pub fn references_to(&self, name: &str) -> Vec<&SourceEntry>
Get all references to a given name.
Sourcepub fn entries_of_kind(&self, kind: &EntryKind) -> Vec<&SourceEntry>
pub fn entries_of_kind(&self, kind: &EntryKind) -> Vec<&SourceEntry>
Get all entries with the given kind.
Sourcepub fn hover_info(&self, line: usize, col: usize) -> Option<HoverInfo>
pub fn hover_info(&self, line: usize, col: usize) -> Option<HoverInfo>
Produce hover information for a given (line, column) position.
Sourcepub fn semantic_tokens(&self) -> Vec<SemanticToken>
pub fn semantic_tokens(&self) -> Vec<SemanticToken>
Produce all semantic tokens for the source map.
Sourcepub fn go_to_definition(&self, line: usize, col: usize) -> Option<Span>
pub fn go_to_definition(&self, line: usize, col: usize) -> Option<Span>
Find the definition of a name and return its span.
Sourcepub fn find_all_occurrences(&self, line: usize, col: usize) -> Vec<&SourceEntry>
pub fn find_all_occurrences(&self, line: usize, col: usize) -> Vec<&SourceEntry>
Find all occurrences (definitions + references) of a name at position.