Skip to main content

SourceMap

Struct SourceMap 

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

The compiler’s registry of source files.

Interning is append-only: once a file has an id its text and path are fixed for the lifetime of the map, which keeps diagnostics and snapshots stable. The map is internally synchronized so it can be shared across threads (the LSP, for example, reads source from a background query thread).

Implementations§

Source§

impl SourceMap

Source

pub fn new() -> SourceMap

Create an empty source map.

Source

pub fn intern( &self, path: impl Into<PathBuf>, text: impl Into<String>, ) -> FileId

Intern a source file under the given path, returning its id.

Each call mints a fresh id even for a repeated path: a later load of the same path is treated as a distinct snapshot. This matches the §13.1 “revisioned source” model — the LSP holds several revisions of one file simultaneously.

Source

pub fn len(&self) -> usize

The number of interned files.

Source

pub fn is_empty(&self) -> bool

True if no files have been interned.

Source

pub fn get(&self, id: FileId) -> Option<FileView>

Fetch a file by id. Returns None for unknown or synthetic ids.

The returned view shares ownership of the file, so it stays valid across later intern calls (which reallocate the Vec) and across threads.

Trait Implementations§

Source§

impl Default for SourceMap

Source§

fn default() -> SourceMap

Returns the “default value” for a type. Read more

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.