pub struct SourceFile { /* private fields */ }Implementations§
Source§impl SourceFile
impl SourceFile
Sourcepub fn load(
abs_path: PathBuf,
root_dir: &Path,
root: SourceRoot,
package: Option<&PackageName>,
overlay: &Overlay,
) -> Result<SourceFile, SourceFileError>
pub fn load( abs_path: PathBuf, root_dir: &Path, root: SourceRoot, package: Option<&PackageName>, overlay: &Overlay, ) -> Result<SourceFile, SourceFileError>
Load a SourceFile from the file system.
root_dir is the directory the file was walked from and root says which of the
package’s two source roots that is; a module’s name is its path under its own
root, so the two roots are walked separately and each file is named relative to
the one it came from.
package is the name of the package root_dir belongs to, and is what the
rendered file name is prefixed with. It is Some whenever the file joins a
database that holds more than one package’s files: a path relative to a
package’s own src/ is not unique across a build — two packages may each hold a
Size.zel — so without it a diagnostic cannot say which package it is about.
None is for a database of exactly one package, where the prefix would be noise.
The text is overlay’s when it holds abs_path, and the file’s otherwise.
pub fn file(&self) -> &SimpleFile<String, String>
Sourcepub fn module_name(&self) -> Name
pub fn module_name(&self) -> Name
The module name this file’s path gives it: src/Js/Basics.zel is Js.Basics.
A module is otherwise called by the name its header declares, and nothing checks the two agree. This is the name a file whose header did not parse is known by.
Sourcepub fn package_path(&self) -> String
pub fn package_path(&self) -> String
Where this file sits in its package: the source root it was walked from and its
path under that root, as src/Model.zel.
This is the half of the rendered name that belongs to the package rather than to the build, and it is what a diagnostic about the package’s own layout — two modules answering to one name — names each file by.