MCPcopy Create free account
hub / github.com/PHPantom-dev/phpantom_lsp / chain_depth

Function chain_depth

src/completion/variable/forward_walk.rs:5836–5861  ·  view source on GitHub ↗

Recursively compute the dependency chain depth for a variable.

(
    var: &str,
    deps: &HashMap<String, HashSet<String>>,
    cache: &mut HashMap<String, u32>,
    visiting: &mut HashSet<String>,
)

Source from the content-addressed store, hash-verified

5834
5835/// Recursively compute the dependency chain depth for a variable.
5836fn chain_depth(
5837 var: &str,
5838 deps: &HashMap<String, HashSet<String>>,
5839 cache: &mut HashMap<String, u32>,
5840 visiting: &mut HashSet<String>,
5841) -> u32 {
5842 if let Some(&cached) = cache.get(var) {
5843 return cached;
5844 }
5845 if !visiting.insert(var.to_string()) {
5846 // Cycle detected — break it.
5847 return 1;
5848 }
5849 let depth = if let Some(rhs_vars) = deps.get(var) {
5850 let mut max_child: u32 = 0;
5851 for dep in rhs_vars {
5852 max_child = max_child.max(chain_depth(dep, deps, cache, visiting));
5853 }
5854 max_child + 1
5855 } else {
5856 1
5857 };
5858 visiting.remove(var);
5859 cache.insert(var.to_string(), depth);
5860 depth
5861}
5862
5863/// Collect assignment dependencies from a statement (cheap AST walk).
5864fn collect_assignment_deps(stmt: &Statement<'_>, deps: &mut HashMap<String, HashSet<String>>) {

Callers 1

assignment_map_depthFunction · 0.85

Calls 3

removeMethod · 0.80
getMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected