From 1a2379a6c24cf903e18cba27a7b0ddfbe75752f9 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Wed, 2 Dec 2026 05:58:31 +0800 Subject: [PATCH] Bound project index scans to the requested directory subtree --- .../texrra-tex-core/src/resources/project.rs | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/crates/texrra-tex-core/src/resources/project.rs b/crates/texrra-tex-core/src/resources/project.rs index c8e78db..c76f25d 100644 --- a/crates/texrra-tex-core/src/resources/project.rs +++ b/crates/texrra-tex-core/src/resources/project.rs @@ -1,7 +1,9 @@ //! Editor-owned immutable logical inputs. Construction and lookup never consult //! the filesystem. Live generated I/O is an explicit, separate host contract. use super::*; -use std::{collections::VecDeque, ffi::OsString, path::Component, sync::OnceLock}; +use std::{ + collections::VecDeque, ffi::OsString, ops::Bound, path::Component, sync::OnceLock, +}; #[derive(Clone, Debug)] pub struct ProjectDefinition { @@ -551,15 +553,27 @@ impl ProjectSnapshot { continue; } ancestors.push(location.path.clone()); + let parent = location.path.as_path(); + // Component ordering keeps a directory's descendants contiguous + // in each collection. Keep the direct-parent check for children. + let bounds = (Bound::Included(parent), Bound::Unbounded); + let in_subtree = |child: &&PathBuf| child.starts_with(parent); let mut names = BTreeSet::new(); for child in self .files - .keys() - .chain(&self.directories) - .chain(self.aliases.keys()) - .chain(live) + .range::(bounds) + .map(|(path, _)| path) + .take_while(in_subtree) + .chain(self.directories.range::(bounds).take_while(in_subtree)) + .chain( + self.aliases + .range::(bounds) + .map(|(path, _)| path) + .take_while(in_subtree), + ) + .chain(live.range::(bounds).take_while(in_subtree)) { - if child.parent() == Some(location.path.as_path()) { + if child.parent() == Some(parent) { if let Some(name) = child.file_name() { names.insert(name.to_owned()); }