Repository: zed-industries/zed
File: crates/project_panel/src/project_panel.rs (Rust)

Code before:
            Default::default();
        let show_diagnostics_setting = ProjectPanelSettings::get_global(cx).show_diagnostics;
        let diagnostic_badges = ProjectPanelSettings::get_global(cx).diagnostic_badges;
        let mut diagnostic_counts: HashMap<(WorktreeId, Arc<RelPath>), (usize, usize)> =
            Default::default();

        if show_diagnostics_setting != ShowDiagnostics::Off {
            // First pass: aggregate per-file counts across all language servers for the same path,
            // so that counts are not inflated when multiple LSPs report diagnostics for one file.
            let mut file_counts: HashMap<(WorktreeId, Arc<RelPath>), (usize, usize)> =
                Default::default();

            self.project
                .read(cx)
                .diagnostic_summaries(false, cx)
                .for_each(|(project_path, _, diagnostic_summary)| {
                    let entry = file_counts
                        .entry((project_path.worktree_id, project_path.path))
                        .or_insert((0, 0));
                    entry.0 += diagnostic_summary.error_count;
                    entry.1 += diagnostic_summary.warning_count;
                });

            for ((worktree_id, path), (error_count, warning_count)) in &file_counts {
                let severity = if *error_count > 0 {
                    Some(DiagnosticSeverity::ERROR)
                } else if show_diagnostics_setting == ShowDiagnostics::All && *warning_count > 0 {
                    Some(DiagnosticSeverity::WARNING)
                } else {
                    None
                };

                if let Some(severity) = severity {
                    let project_path = ProjectPath {
                        worktree_id: *worktree_id,
                        path: path.clone(),
                    };
                    let ancestors = path.ancestors().collect::<Vec<_>>();
                    for ancestor_path in ancestors.iter().rev() {
                        Self::update_strongest_diagnostic_severity(
                            &mut diagnostics,
                            &project_path,
                            (*ancestor_path).into(),
                            severity,
                        );
                    }
                }

                if diagnostic_badges && (*error_count > 0 || *warning_count > 0) {
                    let ancestors = path.ancestors().collect::<Vec<_>>();
                    for ancestor_path in ancestors.iter() {

Review comment (suggestion):
I don't think we need to accumulate diagnostic counts on parent directories. The existing icon decoration already tells you "something in here has diagnostics," and that's sufficient. The actual count on a directory doesn't help much because you still need to drill into files to fix them. I think its just adds visual noise, especially in deep trees where every ancestor ends up with a big number. 

I'd scope `diagnostic_counts` to files only and skip the ancestor propagation.

Code after:
                .context("loading project panel")
                .log_err()
                .flatten()
                .map(|panel| serde_json::from_str::<SerializedProjectPanel>(&panel))
                .transpose()
                .log_err()
                .flatten(),
            None => None,
        };

        workspace.update_in(&mut cx, |workspace, window, cx| {
            let panel = ProjectPanel::new(workspace, window, cx);
            if let Some(serialized_panel) = serialized_panel {
                panel.update(cx, |panel, cx| {
                    panel.width = serialized_panel.width.map(|px| px.round());
                    cx.notify();
                });
            }
            panel
        })
    }

    fn update_diagnostics(&mut self, cx: &mut Context<Self>) {
        let mut diagnostics: HashMap<(WorktreeId, Arc<RelPath>), DiagnosticSeverity> =
            Default::default();
        let show_diagnostics_setting = ProjectPanelSettings::get_global(cx).show_diagnostics;

        if show_diagnostics_setting != ShowDiagnostics::Off {
            self.project
                .read(cx)
                .diagnostic_summaries(false, cx)
                .filter_map(|(path, _, diagnostic_summary)| {
                    if diagnostic_summary.error_count > 0 {
                        Some((path, DiagnosticSeverity::ERROR))
                    } else if show_diagnostics_setting == ShowDiagnostics::All
                        && diagnostic_summary.warning_count > 0
                    {
                        Some((path, DiagnosticSeverity::WARNING))
                    } else {
                        None
                    }
                })
                .for_each(|(project_path, diagnostic_severity)| {
                    let ancestors = project_path.path.ancestors().collect::<Vec<_>>();
                    for path in ancestors.into_iter().rev() {
                        Self::update_strongest_diagnostic_severity(
                            &mut diagnostics,
                            &project_path,
                            path.into(),
                            diagnostic_severity,
                        );