Prepare new macro dependencies without restarting TeX repeatedly
This commit is contained in:
1 parent
46f17f0488
commit
232b0479b3
7 files changed
+187
-32
No files matched your search
@@ -22,6 +22,17 @@ pub(super) fn read_with_date(path: &Path) -> io::Result<(Vec<u8>, Option<SystemT
|
||||
Ok((bytes, modified))
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct PackageDiscovery {
|
||||
expansions: u8,
|
||||
}
|
||||
|
||||
impl PackageDiscovery {
|
||||
pub(super) fn needs_preparation(&self) -> bool {
|
||||
self.expansions >= 2
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct ResourceCapture {
|
||||
resources: BTreeMap<PathBuf, Arc<[u8]>>,
|
||||
@@ -41,6 +52,7 @@ impl ResourceCapture {
|
||||
&mut self,
|
||||
project: &Arc<ProjectSnapshot>,
|
||||
failure: &CompileFailure,
|
||||
package_discovery: Option<&mut PackageDiscovery>,
|
||||
) -> Option<Arc<ProjectSnapshot>> {
|
||||
let trace = failure.trace.as_ref()?;
|
||||
let config = project.configuration();
|
||||
@@ -66,6 +78,7 @@ impl ResourceCapture {
|
||||
let mut queried = BTreeSet::new();
|
||||
let mut added = BTreeMap::new();
|
||||
let mut dates = BTreeMap::new();
|
||||
let mut added_package_file = false;
|
||||
for lookup in trace
|
||||
.lookups
|
||||
.iter()
|
||||
@@ -89,6 +102,11 @@ impl ResourceCapture {
|
||||
if let Some(date) = modified.and_then(|time| FileModificationTime::from_system_time(time).ok()) {
|
||||
dates.insert(path.clone(), date);
|
||||
}
|
||||
added_package_file |= lookup.kind == ResourceKind::Tex
|
||||
&& path.extension().and_then(|value| value.to_str()).is_some_and(|extension| {
|
||||
["sty", "cls", "clo", "def", "cfg", "fd", "ldf"]
|
||||
.iter().any(|known| extension.eq_ignore_ascii_case(known))
|
||||
});
|
||||
added.insert(path, Arc::from(bytes));
|
||||
}
|
||||
}
|
||||
@@ -96,6 +114,16 @@ impl ResourceCapture {
|
||||
return None;
|
||||
}
|
||||
let expanded = project.with_external_resources_and_dates(&added, &dates).ok()?;
|
||||
if let Some(discovery) = package_discovery
|
||||
&& added_package_file
|
||||
{
|
||||
// A single missing input can be captured in place. Another
|
||||
// package-file miss after a retry can indicate a new package tree.
|
||||
discovery.expansions += 1;
|
||||
if discovery.needs_preparation() {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
self.resources.extend(added);
|
||||
self.dates.extend(dates);
|
||||
Some(expanded)
|
||||
|
||||
Reference in new issue
Block a user