MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / go_scoped_fn_ref_scopes

Function go_scoped_fn_ref_scopes

codegraph-kernel/src/go.rs:1616–1653  ·  view source on GitHub ↗

The candidates, by index, that get one reference per scope instead of one per function, each with the id of the scope it sits in: names a function uses at least twice and binds itself. Only those candidates' positions are read from the tree. Mirrors goScopedFnRefScopes.

(cands: &[Cand<'t>], node_ids: &[String], src: &str)

Source from the content-addressed store, hash-verified

1614/// function uses at least twice and binds itself. Only those candidates'
1615/// positions are read from the tree. Mirrors goScopedFnRefScopes.
1616fn go_scoped_fn_ref_scopes<'t>(cands: &[Cand<'t>], node_ids: &[String], src: &str) -> HashMap<usize, usize> {
1617 let mut groups: HashMap<(&str, &str), Vec<usize>> = HashMap::new();
1618 for (i, c) in cands.iter().enumerate() {
1619 if c.name.contains('.') {
1620 continue;
1621 }
1622 groups.entry((node_ids[c.from as usize].as_str(), c.name.as_str())).or_default().push(i);
1623 }
1624 let mut sites: Vec<(usize, usize, Node<'t>)> = Vec::new();
1625 let mut units: Vec<Node<'t>> = Vec::new();
1626 let mut unit_ids: HashSet<usize> = HashSet::new();
1627 let mut names: HashSet<&str> = HashSet::new();
1628 for members in groups.values() {
1629 if members.len() < 2 {
1630 continue;
1631 }
1632 for &i in members {
1633 let (scope, unit) = go_fn_ref_site(cands[i].node);
1634 let Some(unit) = unit else { continue };
1635 sites.push((i, scope, unit));
1636 if unit_ids.insert(unit.id()) {
1637 units.push(unit);
1638 }
1639 names.insert(cands[i].name.as_str());
1640 }
1641 }
1642 let mut out: HashMap<usize, usize> = HashMap::new();
1643 if units.is_empty() {
1644 return out;
1645 }
1646 let bound = go_local_bindings(&units, &names, src);
1647 for (i, scope, unit) in sites {
1648 if bound.contains(&(unit.id(), cands[i].name.clone())) {
1649 out.insert(i, scope);
1650 }
1651 }
1652 out
1653}

Callers 1

Calls 5

go_fn_ref_siteFunction · 0.85
go_local_bindingsFunction · 0.85
pushMethod · 0.80
lenMethod · 0.80
idMethod · 0.80

Tested by

no test coverage detected