Skip to content

Commit

Permalink
Don't exclude template files
Browse files Browse the repository at this point in the history
Also don't crash the CLI when displaying errors on excluded files.

Fix #8
  • Loading branch information
elegaanz committed May 23, 2024
1 parent 721a658 commit db66d2e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/check/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,19 @@ pub async fn check(
name: name.into(),
version,
};

world_for_template(
&manifest,
package_dir,
package_spec.unwrap_or(&inferred_package_spec),
exclude,
exclude.clone(),
)
} else {
None
};

dont_exclude_template_files(diags, &manifest, package_dir, exclude);

Worlds {
package: world,
template: template_world,
Expand Down Expand Up @@ -440,3 +443,42 @@ fn world_for_template(
world.exclude(exclude);
Some(world)
}

fn dont_exclude_template_files(
diags: &mut Diagnostics,
manifest: &toml_edit::ImDocument<&String>,
package_dir: &Path,
exclude: Override,
) -> Option<()> {
let template_root = manifest
.get("template")
.and_then(|t| t.get("path"))?
.as_str()?;
for entry in ignore::Walk::new(package_dir.join(template_root)) {
if let Ok(entry) = entry {
if exclude
.matched(
entry.path().canonicalize().ok()?,
entry.metadata().ok()?.is_dir(),
)
.is_ignore()
{
diags.emit(
Diagnostic::error()
.with_message(
"This file is part of the template and should not be excluded.",
)
.with_labels(vec![Label::primary(
FileId::new(
None,
VirtualPath::new(entry.path().strip_prefix(&package_dir).ok()?),
),
0..0,
)]),
)
}
}
}

Some(())
}
3 changes: 3 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ pub fn print_diagnostics(
// don't remove the exclusion, it will fail to read and display the file
// contents.
world.exclude(Override::empty());
world.reset_file_cache();

println!("writing diags !!!");

for diagnostic in warnings.iter().chain(errors) {
term::emit(
Expand Down
5 changes: 5 additions & 0 deletions src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ impl SystemWorld {
pub fn exclude(&mut self, globs: Override) {
self.excluded = globs;
}

pub fn reset_file_cache(&mut self) {
let mut slots = self.slots.lock();
slots.clear();
}
}

impl World for SystemWorld {
Expand Down

0 comments on commit db66d2e

Please sign in to comment.