Skip to main content

replace_source_discovery_diagnostics

Function replace_source_discovery_diagnostics 

Source
pub fn replace_source_discovery_diagnostics(
    root: &Path,
    diagnostics: Vec<WorkspaceDiagnostic>,
) -> Vec<WorkspaceDiagnostic>
Expand description

Replace every source-discovery diagnostic for root with diagnostics in ONE registry operation, and hand the same list back to the caller.

Called at the END of each source walk (discover_files) so a stale skipped-large-file entry from a previous analysis pass (a watch-mode rerun after the user raised --max-file-size or added the file to ignorePatterns) is dropped while the current walk’s skips are written. Pairs with the preserve in stash_workspace_diagnostics: this call keeps the set CURRENT across reruns, the preserve keeps it ALIVE across combined-mode’s per-analysis config re-loads (issue #1086).

The clear-then-append pair this replaces was two separate lock acquisitions, so a second source walk running concurrently on the same root (combined mode runs the dead-code and duplication walks under rayon::join whenever a per-analysis production split stops them from sharing a file list) could interleave its clear between this walk’s clear and its appends, or between the appends and the walk’s own read-back. Holding the lock across the whole replacement makes the registry state a clean last-writer-wins, and returning the list lets each analysis carry exactly what ITS walk skipped without reading the shared registry back at all (issue #2366).

The retain also drops the parse stage’s source-read-failure entries, because WorkspaceDiagnosticKind::is_source_discovery covers that kind too, so a concurrent walk on the same root can clear a read failure another analysis’s parse recorded. That window closes on its own: record_source_read_failures replaces the read-failure set from each analysis’s own parse, and a fold’s closing registry leg reads after both walks have finished. Narrowing this retain to WorkspaceDiagnosticKind::is_source_walk_recorded would leave the read-failure set to its own recorder entirely.