@@ -34,6 +34,26 @@ function M.toggle_session_lock()
3434 return M .set_session_lock (not M .is_session_locked ())
3535end
3636
37+ --- List sessions in the given scope. Always returns a non-nil array.
38+ --- @param scope ? ' project' | ' global' defaults to project-scoped
39+ --- @return Session[] | GlobalSession[]
40+ function M .list_sessions_by_scope (scope )
41+ if scope == ' global' then
42+ return session .get_all_global_sessions ():await () or {}
43+ end
44+ return session .get_all_workspace_sessions ():await () or {}
45+ end
46+
47+ --- Keep only pickable sessions: non-empty title and matching parent_id.
48+ --- @param sessions Session[] | GlobalSession[]
49+ --- @param parent_id ? string nil selects mainline (no parent ), otherwise children of parent_id
50+ --- @return Session[]
51+ function M .filter_pickable_sessions (sessions , parent_id )
52+ return vim .tbl_filter (function (s )
53+ return s ~= nil and s .title ~= ' ' and s .parentID == parent_id
54+ end , sessions )
55+ end
56+
3757local function focus_after_session_switch (selected_session )
3858 if not state .ui .is_visible () then
3959 M .open ()
5777--- @param parent_id string ?
5878--- @param scope ? ' project' | ' global' when nil , defaults to project-scoped
5979M .select_session = Promise .async (function (parent_id , scope )
60- local all_sessions
61- if scope == ' global' then
62- all_sessions = session .get_all_global_sessions ():await () or {}
63- else
64- all_sessions = session .get_all_workspace_sessions ():await () or {}
65- end
80+ local all_sessions = M .list_sessions_by_scope (scope )
6681 --- @cast all_sessions Session[]
6782
68- local filtered_sessions = vim .tbl_filter (function (s )
69- return s .title ~= ' ' and s ~= nil and s .parentID == parent_id
70- end , all_sessions )
83+ local filtered_sessions = M .filter_pickable_sessions (all_sessions , parent_id )
7184
7285 if # filtered_sessions == 0 then
7386 vim .notify (parent_id and ' No child sessions found' or ' No sessions found' , vim .log .levels .INFO )
0 commit comments