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:1644–1681  ·  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

1642/// function uses at least twice and binds itself. Only those candidates'
1643/// positions are read from the tree. Mirrors goScopedFnRefScopes.
1644fn go_scoped_fn_ref_scopes<'t>(cands: &[Cand<'t>], node_ids: &[String], src: &str) -> HashMap<usize, usize> {
1645 let mut groups: HashMap<(&str, &str), Vec<usize>> = HashMap::new();
1646 for (i, c) in cands.iter().enumerate() {
1647 if c.name.contains('.') {
1648 continue;
1649 }
1650 groups.entry((node_ids[c.from as usize].as_str(), c.name.as_str())).or_default().push(i);
1651 }
1652 let mut sites: Vec<(usize, usize, Node<'t>)> = Vec::new();
1653 let mut units: Vec<Node<'t>> = Vec::new();
1654 let mut unit_ids: HashSet<usize> = HashSet::new();
1655 let mut names: HashSet<&str> = HashSet::new();
1656 for members in groups.values() {
1657 if members.len() < 2 {
1658 continue;
1659 }
1660 for &i in members {
1661 let (scope, unit) = go_fn_ref_site(cands[i].node);
1662 let Some(unit) = unit else { continue };
1663 sites.push((i, scope, unit));
1664 if unit_ids.insert(unit.id()) {
1665 units.push(unit);
1666 }
1667 names.insert(cands[i].name.as_str());
1668 }
1669 }
1670 let mut out: HashMap<usize, usize> = HashMap::new();
1671 if units.is_empty() {
1672 return out;
1673 }
1674 let bound = go_local_bindings(&units, &names, src);
1675 for (i, scope, unit) in sites {
1676 if bound.contains(&(unit.id(), cands[i].name.clone())) {
1677 out.insert(i, scope);
1678 }
1679 }
1680 out
1681}

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