(
root: &Path,
projects: &[crate::global_db::CodeProjectRecord],
)
| 218 | } |
| 219 | |
| 220 | fn match_initialize_root_to_registered_project( |
| 221 | root: &Path, |
| 222 | projects: &[crate::global_db::CodeProjectRecord], |
| 223 | ) -> Option<PathBuf> { |
| 224 | let root = root.canonicalize().unwrap_or_else(|_| root.to_path_buf()); |
| 225 | let mut matches: Vec<_> = projects |
| 226 | .iter() |
| 227 | .filter_map(|project| { |
| 228 | let project_path = PathBuf::from(&project.canonical_root); |
| 229 | let project_path = project_path |
| 230 | .canonicalize() |
| 231 | .unwrap_or_else(|_| project_path.clone()); |
| 232 | (root == project_path || root.starts_with(&project_path)) |
| 233 | .then(|| (project_path.components().count(), project_path)) |
| 234 | }) |
| 235 | .collect(); |
| 236 | matches.sort_by(|a, b| b.0.cmp(&a.0).then_with(|| a.1.cmp(&b.1))); |
| 237 | matches.into_iter().map(|(_, path)| path).next() |
| 238 | } |
| 239 | |
| 240 | /// Cache duration for version checks (15 minutes). |
| 241 | const VERSION_CHECK_INTERVAL: Duration = Duration::from_mins(15); |
no test coverage detected