(root: &Path, path: &Path, out: &mut Vec<FileSig>)
| 53 | }); |
| 54 | } |
| 55 | |
| 56 | pub fn take_project_scan(root: &Path) -> Option<ProjectScan> { |
| 57 | let key = root.to_string_lossy(); |
| 58 | let jobs = PROJECT_SCAN_JOBS.get_or_init(|| Mutex::new(BTreeMap::new())); |
| 59 | let mut guard = jobs.lock().ok()?; |
| 60 | let job = guard.get_mut(key.as_ref())?; |
| 61 | let scan = job.ready.take()?; |
| 62 | // Job is fully consumed (not running, ready drained) -- drop the entry |
| 63 | // instead of leaving a spent placeholder in the map forever. |
| 64 | guard.remove(key.as_ref()); |
| 65 | Some(scan) |
| 66 | } |
| 67 | |
| 68 | /// Drops scan-job entries for any root other than `root`. The editor only |
| 69 | /// ever polls one project root at a time, so entries from a previously |
| 70 | /// opened project would otherwise sit in the map (with a background thread |
| 71 | /// possibly still writing to them) for the rest of the process lifetime. |
| 72 | /// Call on project open/switch. |
| 73 | pub fn retain_project_scan_job(root: &Path) { |
| 74 | let key = root.to_string_lossy().to_string(); |
| 75 | let jobs = PROJECT_SCAN_JOBS.get_or_init(|| Mutex::new(BTreeMap::new())); |
| 76 | if let Ok(mut guard) = jobs.lock() { |
| 77 | guard.retain(|existing_key, _| existing_key == &key); |
| 78 | } |
no test coverage detected