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,removeand 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 byresolve, 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. Atests/that is not on disk does not stop that, but asrc/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
.zelsources go through it. A key that does not end in.zelis 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.zeldiagnostic of the package; a facade’s companion.mjsis read from disk too, by a build that writes, which takes no overlay. - The package has to exist on disk, with its
zelkova.tomland itssrc/, for the overlay to apply to it. A package that exists only in memory is out of scope.