diff --git a/src/graph.rs b/src/graph.rs index 1c9c243..b9bba68 100755 --- a/src/graph.rs +++ b/src/graph.rs @@ -105,6 +105,21 @@ impl Graph { None } + /// Traverses a notes dependencies to get the set of all dependencies, direct and indirect. + pub fn get_nested_deps(&self, id : Id) -> HashSet { + fn helper(graph : &Graph, curr : &Id, output : &mut HashSet) { + for dep in graph.edges.get(curr).unwrap() { + output.insert(*dep); + helper(graph, dep, output) + } + } + + let mut output = HashSet::new(); + helper(self, &id, &mut output); + + output + } + fn find_cycle_local(&self, start : Id, unvisited : &mut BTreeSet, current_path_visited : &mut HashSet) -> Option> { // If already visited in the current path, then there is a cycle diff --git a/src/list.rs b/src/list.rs index 8204807..ae1a16a 100644 --- a/src/list.rs +++ b/src/list.rs @@ -7,7 +7,7 @@ use crate::tasks::Id; use std::cmp; use std::path; -use std::collections::{HashSet, HashMap}; +use std::collections::HashSet; use chrono::SubsecRound; impl args::ListOptions { @@ -128,10 +128,13 @@ pub fn list(mut options : args::ListOptions, vault_folder : &path::Path, state : })); } - // Checks that a task has no incomplete dependencies (these dependencies are direct only). + // Checks that a task has no incomplete dependencies. if options.no_dependencies { tasks = Box::new(tasks.filter(move |t| { - t.data.dependencies.iter().all(|d| completed_ids.contains(&d)) + // Get all dependencies (including indirect ones). + let all_dependencies = state.data.deps.get_nested_deps(t.data.id); + // Check that all of those dependencies are completed. + all_dependencies.iter().all(|d| completed_ids.contains(&d)) })); }