use super::ProjectList;
use super::visible_rows::ExpandKey;
use crate::project::AbsolutePath;
use crate::project::RootItem;
use crate::project::RustProject;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum ExpandTarget {
Root(AbsolutePath),
Group(AbsolutePath, String),
Worktree(AbsolutePath),
WorktreeGroup(AbsolutePath, String),
}
pub(super) fn collect_expandable_targets(list: &ProjectList) -> Vec<(ExpandKey, ExpandTarget)> {
let mut out = Vec::new();
for (ni, entry) in list.iter().enumerate() {
let item = &entry.item;
if entry.has_children() {
out.push((ExpandKey::Node(ni), ExpandTarget::Root(item.path().clone())));
}
match item {
RootItem::Rust(RustProject::Workspace(ws)) => {
for (gi, group) in ws.groups().iter().enumerate() {
if group.is_named() {
out.push((
ExpandKey::Group(ni, gi),
ExpandTarget::Group(
item.path().clone(),
group.group_name().to_string(),
),
));
}
}
},
RootItem::Worktrees(wtg) if wtg.renders_as_group() => {
for (wi, wentry) in wtg.iter_entries().enumerate() {
let RustProject::Workspace(ws) = wentry else {
continue;
};
if ws.has_members() {
out.push((
ExpandKey::Worktree(ni, wi),
ExpandTarget::Worktree(wentry.path().clone()),
));
}
for (gi, group) in ws.groups().iter().enumerate() {
if group.is_named() {
out.push((
ExpandKey::WorktreeGroup(ni, wi, gi),
ExpandTarget::WorktreeGroup(
wentry.path().clone(),
group.group_name().to_string(),
),
));
}
}
}
},
RootItem::Worktrees(wtg) => {
if let Some(RustProject::Workspace(ws)) = wtg.single_live() {
for (gi, group) in ws.groups().iter().enumerate() {
if group.is_named() {
out.push((
ExpandKey::Group(ni, gi),
ExpandTarget::Group(
item.path().clone(),
group.group_name().to_string(),
),
));
}
}
}
},
RootItem::Rust(RustProject::Package(_)) | RootItem::NonRust(_) => {},
}
}
out
}