Skip to main content

Overlay

Struct Overlay 

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

The text of the buffers an editor holds open, to be read in place of what is on disk.

A module’s text normally comes from its file. A language server checks what the editor holds, which differs from the disk until the user saves, so the checking entry points (check_package and check_package_with_tests) take an Overlay and every .zel file is read through it. The functions that write a build take none: no build is ever written from the text of a buffer.

An Overlay is a concrete type and not a trait, because it is the only source of text other than the disk anything wants. The functions that take it take an &Overlay where a &dyn would go, so making it one later changes a type and no call graph.

The rules, which outlive the ticket (TOOL-2) that set them:

  • A path is normalised before every comparison, on both sides. insert, remove and every lookup canonicalize the deepest ancestor of the path that exists on disk and append the rest unchanged, so a path that is not on disk yet still normalises. The two sides are spelled differently otherwise: package roots are canonicalized by resolve, so a walk yields paths under the canonical root, while a caller’s path is whatever its editor reported (/tmp/.. against /private/tmp/.. on macOS). The walk follows symbolic links, so a file reached through one is matched by where it points. Normalisation is for the lookup only: a module is still named from the path the walk yielded.
  • The walk adds what only the overlay holds. After the walk of a source root, every key that ends in .zel, sits under the normalised form of that root and was not matched by a walked file is loaded too, in path order, and named by its path under the normalised root. A tests/ that is not on disk does not stop that, but a src/ that is not on disk is the error it always is, whatever the overlay holds.
  • It only replaces and adds. There is no way to say a file on disk is gone: an editor that deletes a module deletes the file, and the next walk does not find it.
  • Only .zel sources go through it. A key that does not end in .zel is ignored, so a caller may hand over every open buffer unfiltered. The manifest is read from disk, because one being typed is malformed most of the time and its error would clear every .zel diagnostic of the package; a facade’s companion .mjs is read from disk too, by a build that writes, which takes no overlay.
  • The package has to exist on disk, with its zelkova.toml and its src/, for the overlay to apply to it. A package that exists only in memory is out of scope.

Implementations§

Source§

impl Overlay

Source

pub fn new() -> Overlay

An overlay holding no buffer: every file is read from disk.

Source

pub fn insert(&mut self, path: impl AsRef<Path>, text: String)

Hold text as the contents of the file at path, replacing any earlier text for the same file.

Source

pub fn remove(&mut self, path: impl AsRef<Path>) -> Option<String>

Stop holding the file at path, so it is read from disk again. Returns its text if it was held.

Trait Implementations§

Source§

impl Clone for Overlay

Source§

fn clone(&self) -> Overlay

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Overlay

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Overlay

Source§

fn default() -> Overlay

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.