pub struct SourceMap { /* private fields */ }Implementations§
Source§impl SourceMap
impl SourceMap
pub fn new() -> SourceMap
pub fn add( &mut self, name: impl Into<String>, text: impl Into<String>, ) -> FileId
pub fn name(&self, file: FileId) -> &str
Sourcepub fn find(&self, name: &str) -> Option<FileId>
pub fn find(&self, name: &str) -> Option<FileId>
The file this map holds under name, if it holds one.
For a caller that has a span and needs to know which file it is in rather than what it
says: an editor answering a question about one document holds spans from every module the
project linked, and two files’ byte offsets overlap by construction. Compares whole names
rather than suffixes, because a FileId that is nearly right is a span pointing into the
wrong buffer.
pub fn text(&self, file: FileId) -> &str
Sourcepub fn line_col(&self, file: FileId, offset: u32) -> (usize, usize)
pub fn line_col(&self, file: FileId, offset: u32) -> (usize, usize)
1-based line and column (column counted in characters, not bytes).
A span from a file this map does not hold reports 1:1 rather than panicking. That is a
compiler defect wherever it happens — a diagnostic that cannot be located is a diagnostic
nobody can act on — but the failure belongs in the message, not in a crash during rendering.