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:1618–1655  ·  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

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

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